开发者

how to access a specific list item without knowing the index in JQuery

开发者 https://www.devze.com 2023-03-18 23:34 出处:网络
i have a long list tha开发者_StackOverflowt\'s divided among number of subheadings. how can i access the last element of the list before certain subheading given that its not the last element of the

i have a long list tha开发者_StackOverflowt's divided among number of subheadings. how can i access the last element of the list before certain subheading given that its not the last element of the list. ? can i do that if i have the subheading ID

i.e.

<ol>
    <h1 id="heading1"> Heading 1 </h1>
    <li> bla bla bla </li>
    <li> bla bla bla </li>
    <li> I WANT TO ACCESS THIS </li>
    <h1 id="heading2"> Heading 2 </h1>
    <li> bla bla bla </li>
    <li> bla bla bla </li>
</ol>


You can use the heading selector and use .prev

$('#heading2').prev()

Reference from the jQuery api: http://api.jquery.com/prev/

p.s. H1 inside a list will not validate.

0

精彩评论

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

关注公众号