dynamically href link to next sibling on ul tree
Im using Javascript, but not Jquery or other frameworks. Id rather lose the weight as there are only a few functions in the program. I am trying something a bit like this guy: Get the next href in a list in another file with jQuery?
I will have a load of separate HTML pages but they will be linked to their Siblings. I am basically looking for a dynamic way to do previous and next links for each page, to link to their siblings.
For example:
<ul><li>1
<ul><li>a</li>
<li>b</li></ul></li>
<li>2
<ul><li>c</li>
<li>d</li></ul></li>
<ul>
If Im on page b the next will take me to c. And if I'm on c the same button will take me to d etc.
I should be able to generate the href for the next page using something form this page: How to get first href link of li in a ul list in jQuery For example
var url = $("ul a:eq(0)").attr("href");
But how would I find some sort of .this in the < ul > tree th开发者_StackOverflow中文版e page Im on right now, so I know to go to the next link? Is there some sort of find this html on ul ?
Break the problem down:
- Analyse what page you're on (possibly using the window.location object)
- Find that node in the menu
- Find the next and previous nodes
- Generate your links
精彩评论