How to find div into a div?
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 alldiv
inside contenu including other nesteddiv
s$('#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();
});
精彩评论