views:

236

answers:

3

HTML:

<div id="panel">
  <table>
    <tr>
       <td><input id="Search_NazovProjektu" type="text" value="" /></td>
    </tr>
    <tr>
       <td><input id="Search_Popis" type="text" value="" /></td>
    </tr>
  </table>
</div>

I need to select all inputs in the particular div.

This's not working:

var i = $("#panel > :input");
+2  A: 

Use it without the greater than:

$("#panel :input");

The > means only direct children of the element, if you want all children no matter the depth just use a space.

Nick Craver
Interesting... Now I'm confused... The `:` is for pseudo-classes, isn't it? But we want to select an element type. Why the `:`?
mnemosyn
@mnemosyn - This is another type of selector like `:checkbox' is, see here for details: http://api.jquery.com/input-selector/ And here's a more complete list of these: http://api.jquery.com/category/selectors/form-selectors/
Nick Craver
Thanks Nick, wasn't aware of that. Fixed my answer.
mnemosyn
+3  A: 

You need

var i = $("#panel input"); 

or, depending on what exactly you want (see below)

var i = $("#panel :input"); 

the > will restrict to children, you want all descendants.

EDIT: As Nick pointed out, there's a subtle difference between $("#panel input") and $("#panel :input).

The first one will only retrieve elements of type input, that is <input type="...">, but not <textarea>, <button> and <select> elements. Thanks Nick, didn't know this myself and corrected my post accordingly. Left both options, because I guess the OP wasn't aware of that either and -technically- asked for inputs... :-)

mnemosyn
+1  A: 
var i = $("#panel input");

should work :-)

the > will only fetch direct children, no children's children
the : is for using pseudo-classes, eg. :hover, etc.

you can read about available css-selectors of pseudo-classes here: http://docs.jquery.com/DOM/Traversing/Selectors#CSS_Selectors

henchman
@henchman - `:input` is a selector as well, http://api.jquery.com/category/selectors/form-selectors/ If he had a `<textarea>` or button `input` would not find it, `:input` would, so there is a difference.
Nick Craver
+1 , so leaving out > will do the trick. now i also found it on the page i recommended....
henchman