开发者

How to find div into a div?

开发者 https://www.devze.com 2023-03-22 01:59 出处:网络
I try to get all the div (some div are append by ajax) into a parent div (to hide开发者_如何学运维 them). I\'ve readed some documentation, but this not works :

I try to get all the div (some div are append by ajax) into a parent div (to hide开发者_如何学运维 them). I've readed some documentation, but this not works :

<div id="contenu">            
 <div id="formFile"></div>
 <div id="documents"></div>
 <div id="options"></div>
 <div class="clear"></div>
 <div id="box_import"></div>
 <div class="clear"></div>
</div>

$('div#contenu ~ div').each(function(index){
   alert($(this).attr('id'));
});

Have you an idea ?


Use this:

$('#contenu div').each(function(index){
   alert($(this).attr('id'));
});

Note:

  • $('#contenu div') will give all div inside contenu including other nested divs
  • $('#contenu > div') will give only the immediate children div


$('div#contenu > div').each(function(index){
   alert(this.id);
});

This gets all divs directly under #contenu and alerts their ID

Fiddle: http://jsfiddle.net/maniator/LKRkS/


$('#contenu').find('div').each(function(index){
   alert($(this).attr('id'));
});


What you have currently will alert their ID... If you want to hide them instead, why not hide the parent?

$(document).ready(function(){
    $("#contenu").hide();
});
0

精彩评论

暂无评论...
验证码 换一张
取 消