addClass() to an object via an external link

Asked

Viewed 48 times

0

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

Slide is active when it is with Class selected, then my idea is this:

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

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

And so on and so forth ...

So in short, how do I get this addCLass() to work after loading the Y page.

In case it’s not too clear I edit.

Thank you.

  • You want to save which item will receive the new class?

  • I want to click on link 1 and it adds a class on Slide 1 and so on ... @Laerte

  • So both are on different pages, link 1 page X and slide 1 page Y ... @Laerte

  • Ué, passes by parameter in the URL, the choice. paginY? slide=1, paginY? slide=2

  • If different pages have to be by url or with Submit.

1 answer

1

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

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

and on the 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 say, I can add more details right when I get off work.

  • use sessionStorage is a good solution too, no?

  • 1

    @Laerte yes, cookie would also. Then you need to intercept the redirect to write first before the browser changes page.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.