如何循环仅在其子节点中具有特定类的元素?
如何循环元素仅在其子节点中具有特定类?
例如,
<ul class="item">
<li class="url">A1</li>
<li class="limit">A2</li>
</ul>
<ul class="item">
<li>3</li>
<li>4</li>
</ul>
<ul class="item">
<li class="url">B1</li>
<li class="limit">B2</li>
</ul>
<ul class="item">
<li>3</li>
<li>4</li>
</ul>
我只想选择这两个,
<ul class="item">
<li class="url">A1</li>
<li class="limit">A2</li>
</ul>
<ul class="item">
<li class="url">B1</li>
<li class="limit">B2</li>
</ul>
我正在处理的这段代码将循环每个 .item
$('.item').each(function(){
var object = $(this);
var title = $('.title',object).text();
var limit = $('.limit',object).text();
alert(url);
});
有什么想法吗?
How can loop the element has a certain class only in its children nodes?
for instance,
<ul class="item">
<li class="url">A1</li>
<li class="limit">A2</li>
</ul>
<ul class="item">
<li>3</li>
<li>4</li>
</ul>
<ul class="item">
<li class="url">B1</li>
<li class="limit">B2</li>
</ul>
<ul class="item">
<li>3</li>
<li>4</li>
</ul>
And I just want to select these two,
<ul class="item">
<li class="url">A1</li>
<li class="limit">A2</li>
</ul>
<ul class="item">
<li class="url">B1</li>
<li class="limit">B2</li>
</ul>
this code I am working on will loop each .item
$('.item').each(function(){
var object = $(this);
var title = $('.title',object).text();
var limit = $('.limit',object).text();
alert(url);
});
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您可以使用
:has()
选择器:请参阅 http:// api.jquery.com/has-selector/
I think you can use the
:has()
selector:See http://api.jquery.com/has-selector/