There are two files with scripts. In one there is a function. And how in another script to call a function that is in the first script? Thanks for answers)
The first script:
function compareInit() { new InSales.Compare({ _textAdd: 'Добавлено', _textLink: 'К сравнению', selector: 'a.add_to_compare', draw: function(products) { if (products.length == 0) { $('.compare-notice').slideDown(); $('#compare_div').slideUp('fast'); } var compareCount = $('#compare_table .item').length; var compareCountNames = 'товар'; if (compareCount > 1) { compareCountNames = 'товара'; } var compareCountMsg = 'Вы сравниваете ' + compareCount + ' ' + compareCountNames $('.compare_count').html(compareCountMsg); if (!$("#compare_table .same").length) { $(".compare_show_similar, .compare_hide_similar").hide(); } else { $(".compare_show_similar, .compare_hide_similar").show(); } var text = ''; console.log(products.length) if (products.length == 0) { text += '<div class="noforcompare">Нет товаров для сравнения</div>'; $('#compare_div').html('<p>Товары для сравнения не выбраны</p><p><a href="/" class="button" title="На главную">На главную</a></p>'); } else { text += '<ol id="compare-items">' $(products).each(function(index, product) { text += '<li class="item odd"><a href="javascript:;" rel="' + product.id + '" class="remove_compare btn-remove">удалить</a><p class="product-name"><a href="/product/?product_id=' + product.id + '">' + product.title + '</a></p></li>'; }); text += '</ol><div class="actions"><button type="button" class="button" onclick="location.href = \'/compares\'"><span><span>Сравнить</span></span></button></div>' } $('.block-compare .block-content').html(text); } }); } compareInit(); $(document).on("click", "a.add_to_compare", function(e) { e.preventDefault(); }); $(document).on("click", ".compare_show_similar", function() { $('.compare_links a').removeClass('active'); $(".compare_show_similar").addClass('active'); $("#compare_table .same").show(); }); $(document).on("click", ".compare_hide_similar", function() { $('.compare_links a').removeClass('active'); $(".compare_hide_similar").addClass('active'); $("#compare_table .same").hide(); }); $(document).on("click", '.compare_clear a', function() { show_preloader(); $.cookie('compare', null); $('.compare-notice').slideDown(); $('#compare_div').slideUp('fast'); hide_preloader(); }); The second script:
$(document).ready(function () { attachClickEvent(); }); var pInfScrLoading = false; var pInfScrDelay = 250; function pInfScrExecute() { pInfScrNode = $('.more').last(); pInfScrURL = $('.more a').last().attr("href"); if(pInfScrNode.length > 0 && pInfScrNode.css('display') != 'none') { $.ajax({ type: 'GET', url: pInfScrURL, beforeSend: function() { pInfScrLoading = true; pInfScrNode.clone().empty().insertAfter(pInfScrNode).append('<img src=\"https://assets3.insales.ru/assets/1/3389/732477/v_1482567929/build/loader.gif\" />'); pInfScrNode.hide(); }, success: function(data) { pInfScrNode.next().remove(); pInfScrNode.remove(); var filteredData = $(data).find(".category-products"); filteredData.insertBefore( $("#product-list-foot") ); $('.pages_my').html($(data).find('.pages_my').html()); compareInit(); pInfScrLoading = false; attachClickEvent(); }, dataType: "html" }); } } $("body").on("click", ".more a", function() { return run_filter($(this).attr("href")); }); function attachClickEvent(){ $('p.more a').click(function(event){ pInfScrExecute(); event.stopPropagation(); return false; }); } Run in order - 1 then 2. You need to run the compareInit(); function in the second script compareInit();
}) is not closed. And in the second, why don't you call it in success? - Yuri