I am new to jQuery. In the below code, I am trying to do a pagination for each sub header, If i click sub header 1, the page should show only the content of sub header 1. I have already tried and got the number of pages that has to be created and got the index.
How can i create pagination ? Like in the below case, i want “1,2,3” to be displayed because there are three sub headers. And on clicking 1, i should show only sub header 1 and the others should be hidden. How can it be done using jQuery?
<span>Click a Header!</span>
<div><h2>Sub Header 1</h2></div><div>Content 1</div>
<div><h2>Sub Header 2</h2></div><div>Content 2</div>
<div><h2>Sub Header 3</h2></div><div>Content 3</div>
$("h2").click(function () {
// this is the dom element clicked
var index = $("h2").index(this);
var size = $("h2").size(this);
$("span").text("That was Header index #" + index + " Total Pages #" + size);
});
Is this what you are trying to achieve?
Explanation:
H2s, except the clicked one, go to parent (DIVcontaining theH2s), get next element (DIVwith content), hide all theDIVs containing contentH2, traverse in the similar manner, make sure theDIVwith content is shown