I have a span tag in html and this <span>
can appear multiple times on the page.
I want to select only the first span tag. I am doing it like this
var $myvar= $(".mydiv .indiv .myspan:first");
For now its working fine.
I think my code will prevent the browser from traversing the whole DOM, as I am using :first,
which will improve performance. Am I correct?
One more question:
HTML:
<div class="mydiv">
<div class="indiv">
<span>myspan</span>
<a href="#" class="anc1">a1</a>
<a href="#" class="anc2">a2</a>
</div>
<table>
..................
</table>
</div>
This html is having 2 anchor tags.I want to write a function on click of this 'a' tag.For that I can try something like $(".mydiv .indiv a").click(function(e) and it will work.but lets say, there is a same repeating structure in HTMl , so it will work for repeating set 'a' tags also, which i dont want.I want only the first set of 'a' tags to work. The functionality of 'a' tag is , onload 2 nd one will be in hide state, so on click of 1st, the 2nd one will be dispalyed and first one will be in hide state,and on click of 2 nd reverse action will happen, hope this time i have made myself clear :-)