[jQuery] Issues with Backwards Traversing the DOM
So I'm having an issue attempting to traverse back in a <li> element
to grab the text inside a header tag and insert that text as the
"title" attribute's value in a link. The markup will more more sense:
<div id="mainCol">
<ul>
<li>
<h1>Header 1</h1>
Some nice text here.
<a href="url" title="">Click Here!</a>
</li>
<li>
<h1>Header 2</h1>
Some nice text here.
<a href="url"></a>
</li>
</ul>
</div> <!-- End of Main Column -->
$(document).ready(function(){
// Add title to each link in the main content column's unordered list
for each list element by using the h1 tag's text.
$('#mainCol ul li a').each(function(){
// Grab the header text of this link's header parent
$(this).parents().size());
});
}); // End of ready function.
Clearly this script won't execute what I need, but the size is 0 and I
can't seem to traverse up the DOM to grab the <h1> tag's text with
combinations using parent, parents, siblings, etc.. Any suggestions?