开发者

dynamically href link to next sibling on ul tree

开发者 https://www.devze.com 2023-04-06 18:46 出处:网络
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 lis

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:

  1. Analyse what page you're on (possibly using the window.location object)
  2. Find that node in the menu
  3. Find the next and previous nodes
  4. Generate your links
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号