Possible Duplicate:
Check that element is in DOM or not with jQuery?
So I have a function, that serves to navigate up two levels with .parent().parent(), then it moves to the next node in the document with .next() and finally grabs the attribute I need from a nested a with .find('a').attr('data-record-id') and that’s all fine and dandy, but now I need to find if the <a></a> element even exists, if not I need to hide the header relating to it. A mockup of the layout is as such:
<html>
<head><title>My Title</title></head>
<body>
<h4 class="dragable">2012-08-20<span style='display: none'><a class='delete-btn'></a></span></h4>
<ul>
<li>
<div>
<div>
<a data-record-id="9">97 bpm</a>
</div>
</div>
</li>
</ul>
</body>
</html>
So given that layout what’s the best way to determine if the <a></a> element exitst, if not, then hide/delte the h4 class relating to it.
$(selector).find('a')is returning an array, no matter if a exists or not. You can easily test with$(select).find('a').length (or .size() ). How this helps.