There is a code to update part of the page without reloading. When you click one link, it always remains active, but the only thing I can’t do is that when you open the page, the active activ_but link remains constantly open. It was proposed to use the trigger, but something I can not

$(document).ready(function(){ var user = <?=$uss?>; var ser = <?=$id_s?>; $('.watch-s a').click(function(e) { e.preventDefault(); $('.watch-s .activ_but').removeClass('activ_but'); $(this).addClass('activ_but'); if ($('#knopa1').attr('class') == 'activ_but'){ $.ajax({ } }); } if ($('#knopa2').attr('class') == 'activ_but'){ $.ajax({ } }); } if ($('#knopa3').attr('class') == 'activ_but'){ $.ajax({ } }); } if ($('#knopa4').attr('class') == 'activ_but'){ $.ajax({ } }); } var rzd = $(this).attr("rzd"); jQuery.ajax({ }); }); }); 

  • What does "link permanently open" mean? In general, it is not clear what you need and it is not clear that the code you are submitting does not work. Specify - ArchDemon
  • when I click on a link on a page (for example, page.php), another dynamic part of the page appears, and I need to, when entering page.php page, one of the dynamic parts is already open (the one that has an activ_but class) - Alex Prosto
  • I advise you not to reinvent the wheel, but use the jquery.tabs plugin. - ArchDemon

1 answer 1

 $(function() { $("#urls a").each(function() { if ($(this).hasClass("active")) { $("#content").load($(this).attr("href")); } }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="urls"> <a class="active" href="index.html">active</a> <br> <a class="notactive" href="page.html">not active</a> </div> <div id="content"></div> 

  • Still done with triggle, but thank you, your script suggested the correct idea $ (function () {$ (". Watch a"). Each (function () {if ($ ('# btn1'). HasClass ("activ_but" )) {$ ('# btn1'). trigger ('click');} - Alex Prosto