addClass () to an object via an external link

0

I need to create a click () function for 8 links that are in pagina X , each link will take me to a specific slide in a pagina Y .

The slide is active when it is with Class selected , so my idea is as follows:

The user clicks on link 1 on page X is taken to page Y with slide 1 active.

The user clicks on link 2 on page X is taken to page Y with slide 2 active.

And so it goes ...

So summarizing, how do I make this addCLass () work after loading the Y page.

If it has not been very clear I edit.

Thank you.

    
asked by anonymous 29.04.2016 / 04:09

1 answer

2

The idea that occurs to me is to pass on the query string link in order to analyze on the arrival page which slide the class should receive. For example:

<a href="/link?slide=1">Slide 1</a>
<a href="/link?slide=2">Slide 2</a>

and slide page:

var slide = location.search.match(/slide=(\d+)/)[1];
var slides = document.querySelectorAll('.slides');
slides[slide].classList.add('selected');

That's the skeleton. If you need help implementing implement, I can add more details as soon as I leave work.

    
29.04.2016 / 13:41