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.
精彩评论