Need some Advice on how to reference elements with jQuery (DOM/Traversing/Selectors). Sometimes its just enough to set an id at the desired element and do this:
$('#elementID').hide();
But sometimes it just cant be used, for example when working with list of n elements, i have seen some people attach a class to each element of the list like:
<a class="selectMe" href="http://jquery.com/">jQuery1</a>
<a class="selectMe" href="http://jquery.com/">jQuery2</a>
<a class="selectMe" href="http://jquery.com/">jQuery2</a>
And then do this with jQuery:
$('.selectMe').hide();
Some other do the same but with rel attribute and so on..
Some other people do this so generic that is scary, if this is the scenario:
<div id="MyID">
<span>Some Text Here</span><a href="http://jquery.com/">jQuery1</a>
</div>
If i Want to attach an event to the anchor:
$('#MyID a').show();
Like assuming that there will be just 1 link inside that DIV.
What you guys think it really depends totally on the scenario or there are some good practices to do this.