我想迭代查询选择器的结果.
<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
原文地址:https://www.jb51.cc/jquery/151090.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。