Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select everything inside a div with jquery?

Ok, so I have a div with a few elements in it and I want to toggle them all, but in my jquery code I have to call all these elements. How can I select them instead of call all of the elements ids? I have to toggle something like this:

<div id="divtotoggle">
    <input type="text" id="textinput" />
    <input type="button" id="button />
    <div id="feedback"></div>
</div>
like image 787
martintrapp Avatar asked Feb 07 '12 18:02

martintrapp


1 Answers

If you only want to toggle the immediate children of your <div> element, you can use the aptly-named children() method to match them:

$("#divtotoggle").children().toggle();

If you want to toggle all the descendant elements (which does not make much sense to begin with, as others rightfuly pointed out in the comments below), you can use an All selector:

$("#divtotoggle *").toggle();
like image 194
Frédéric Hamidi Avatar answered Sep 29 '22 13:09

Frédéric Hamidi