On the main page of the site there are links to the page with services. On the services page there is an accordion, which contains hidden lists of services, and is revealed by clicking on the corresponding title.

The task is to move to another page and at the same time open the corresponding tab with services.

How to do this with js?

3 answers 3

It is possible without using a script. One anchor and target function:

p {display: none;} p:target {display: block;} 
 <a href="#elem0">ะžั‚ะบั€ั‹ั‚ัŒ ั‡ะฐัั‚ัŒ 1</a> <a href="#elem1">ะžั‚ะบั€ั‹ั‚ัŒ ั‡ะฐัั‚ัŒ 2</a> <a href="#elem2">ะžั‚ะบั€ั‹ั‚ัŒ ั‡ะฐัั‚ัŒ 3</a> <p id="elem0">ะงะฐัั‚ัŒ 1</p> <p id="elem1">ะงะฐัั‚ัŒ 2</p> <p id="elem2">ะงะฐัั‚ัŒ 3</p> 

  • Without a script you can not, because elements are on different pages - Marina Voronova
  • @MarinaVoronova, use the methods listed below - Yuri

HTML

 <ul> <li id="tab1">Tab</li> <li id="tab2">Tab2</li> <li id="tab3">Tab3</li> </ul> 

You can solve this problem with anchors (anchor), i.e. you redirect the user to the service link and add an anchor at the end of the URL, for example

 www.vashsite.ru/uslugi#tab3 

After that, on the services page, you through JS check whether there is an anchor

 var anchor = window.location.hash.split('#'); 

if(anchor[1] != ''){$('ul li').slideUp(); $('#'+anchor[1]).slideDown();}

    I did this:

    I pass in the link id

     <a href="services.html#hygiene"></a> 

    In js I check:

     var hash = window.location.hash; $('.card a').each(function(){ if($(this).attr('href') == hash){ $(this).trigger('click'); } });