Jquery.每个分区通过另一个分区内的分区

Jquery .each through Divs inside another Div

本文关键字:分区 另一个 Jquery      更新时间:2023-11-04

我目前有以下html:

抱歉编辑,我写这篇文章的时候没有注意。

 <div class ="left">
    <div>1</div>
    <div>2</div>
    <div>3</div>
</div>

我使用JQuery.each命令使用$('div').each迭代每个div。尽管我只想在类名为"left"的div中迭代div。

我尝试过使用$('.left > div').each,但它不起作用。

感谢您的帮助。

$.each( $('.left'), function(i, left) {
   $('div', left).each(function() {
   });
})

这就是你想要的吗?

$('div.left>div').each(function(){ /* do stuff */ });

Fiddle:http://jsfiddle.net/MLnBY/

$(".left").children().each(function(i, elm) {
    alert($(this).html())
});

语法应该是$(".left > div").each(function(){});而不是.each(".left > div")

更新:想要使用$(".left").children().each()