-2

I try to run js code after data load it work's conversely now first it's run code, before load data, and delete class .active, I need delete class after click on another link

here is my code:

 $('document').ready(function() {
            $('.links a').click(function(e) {
                e.preventDefault();
                $('.links a').not(this).removeClass('active');
                $(this).addClass('active');
            });
        });
        function Animate2id(id) {
            // your function stuff
        }

and my html:

<div class ="links">
        <a id="section-<?=$arParams['CODE']?>-link" href="#" onclick="ajax_load('#no-scroll-items-<?=$arParams['CODE'];?>', '<?=$arResult['AJAX_CALL_ID']?>', 'do=select_section&id=<?=4610?>'); return false;" class="" title="Мобильные телефоны">Мобильные телефоны</a>
        <a id="section-<?=$arParams['CODE']?>-link" href="#" onclick="ajax_load('#no-scroll-items-<?=$arParams['CODE'];?>', '<?=$arResult['AJAX_CALL_ID']?>', 'do=select_section&id=<?=4611?>'); return false;" class="" title="Планшеты">Планшеты</a>
        <a id="section-<?=$arParams['CODE']?>-link" href="#" onclick="ajax_load('#no-scroll-items-<?=$arParams['CODE'];?>', '<?=$arResult['AJAX_CALL_ID']?>', 'do=select_section&id=<?=4616?>'); return false;" class="" title="Монопады">Монопады</a>
        <a id="section-<?=$arParams['CODE']?>-link" href="#" onclick="ajax_load('#no-scroll-items-<?=$arParams['CODE'];?>', '<?=$arResult['AJAX_CALL_ID']?>', 'do=select_section&id=<?=4630?>'); return false;" class="" title="Наушники">Наушники</a>
        <a id="section-<?=$arParams['CODE']?>-link" href="#" onclick="ajax_load('#no-scroll-items-<?=$arParams['CODE'];?>', '<?=$arResult['AJAX_CALL_ID']?>', 'do=select_section&id=<?=4739?>'); return false;" class="" title="Медиаплееры">Медиаплееры</a>
        <a id="section-<?=$arParams['CODE']?>-link" href="#" onclick="ajax_load('#no-scroll-items-<?=$arParams['CODE'];?>', '<?=$arResult['AJAX_CALL_ID']?>', 'do=select_section&id=<?=4593?>'); return false;" class="" title="Аксессуары">Аксессуары</a>
    </div>

what I missing? best regards

2 Answers2

0

Try this:

$('document').ready(function() {
   $('.links a').on('click', function(){
      $('.links a').removeClass('active');
      $(this).addClass('active');
   });
});

live demo: codepen

Abdullah Al Shakib
  • 2,034
  • 2
  • 15
  • 16
0
$(document).ready(function() {
     // executes when HTML-Document is loaded and DOM is ready
     alert("document is ready");
    });


    $(window).load(function() {
     // executes when complete page is fully loaded, including all frames, objects and images
     alert("window is loaded");
    });

otherwise use settimeout

setTimeout(function(){ alert("call after 3000 mili sec"); }, 3000);
Karan Singh
  • 876
  • 1
  • 6
  • 12