我想迭代查询选择器的结果.
<nav id="navigation"> <a href="#" tabindex="1" class="active_nav">nav1</a> <a href="#" tabindex="2">nav2</a> <a href="#"tabindex="3">nav3</a> </nav>
当我使用javascript
alert($("#navigation >a")[0]);
解决方法
使用$.each
$("#navigation > a").each(function() { console.log(this.href) });
$('#navigation > a')[0] ^ ^---- Selects the 1st dom object from the jQuery object | that is nothing but the index of the element among | the list of elements |------- Gives you children of nav(3 anchor tags in this case) which is a jQuery object that contains the list of matched elements