[英]How can I select a parent element, and all child divs that are not the first, as well as siblings of the parents and their children
[英]How do I select these children divs
我试图提醒每个div的ID,所以输出11 25 78
。
<div id="main">
<div id="section-11">Some content</div>
<div id="section-25">Some content</div>
<div id="section-78">Some content</div>
</div>
我已经选择了main
,我正在尝试使用children
但它不起作用。 不知道为什么。
$('#main').children().each(function(){
alert($(this).attr('id'));
});
$('#main div').each(function() {
alert($(this).attr('id').replace(/section-/, ''));
});
它至少在FF中起作用。 看看这个JSFiddle
我想那里有更多嵌套的div
元素,即那些“section”元素不是主面板的直接子元素?
在这种情况下,有这样的选择器:
$('#main div[id^="section-"]').each(function(){
查找所有匹配的元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.