Hello I got a question regarding setting the display of a div with the use of the data-target attribute. I have the following HTML code:
<div class="page page-current" id="home">
PAGE 1
<a href="#" class="next" data-target="#about">Go to about</a>
</div>
<div class="page page-section" id="about">
PAGE 2
<a href="#" class="next" data-target="#portfolio">Go to portfolio</a>
</div>
<div class="page page-section" id="portfolio">
PAGE 3
</div>
As can seen above, the div's that contain the class: page-section are initial hidden by CSS using: display:none. Now I managed to create a generic JS code that checks which div should be made visible:
$(".next").click(function(){
var target = $(this).data("target");
$(target).addClass("page-current");
})
The problem with this is that it adds to the second div the class: page-current but the first div also still contains this class.
Can anyone guide me in the right direction how I could solve this is in a generic way so that only one div at the time can contain the class: page-current
I have created a JSFIDDLE of this problem.