jquery - index of click element on the list is different on IE 7
- by surajz
cms is generating content in this format.
<ul id="slide_nav" class="tabs">
<a name="ctn2363_2465" id="ctn2363_2465" class="hidden"></a><li id="button_1"><a class="ohlord" href="javascript: void(0);" id="b1">Bookbag</a></li>
<a name="ctn2363_2466" id="ctn2363_2466" class="hidden"></a><li id="button_2"><a class="ohlord" href="javascript: void(0);" id="b2">help</a></li>
<a name="ctn2363_2467" id="ctn2363_2467" class="hidden"></a><li id="button_3"><a class="ohlord" href="javascript: void(0);" id="b3">Team</a></li>
<a name="ctn2363_2468" id="ctn2363_2468" class="hidden"></a><li id="button_4"><a class="ohlord" href="javascript: void(0);" id="b4">At</a></li>
</ul>
To get a correct index of the clicked link I have to do this in IE 7 (use class info in selector)
$("#slide_nav li a").click(function(){
var index = $("#slide_nav li > a.ohlord").index(this);
});
On firefox $("#slide_nav li > a").index(this); works. On IE this produces incorrect index (0, 2, 4, 6 ..). Is there a way to get the correct index in IE 7 for the above html without using class information in the selector?
My second question is
$('#slides img')[index].attr('style', 'display: block;');
does not work. I have to iterate through each $('#slides img') elements to set the attribute. Isn't HTMLElement object returned from $('#slides img')[index] an jquery object?