4

I want to loop through all my input elements and select elements in one loop but this doesn't work.

$('#blockProperties :input :select').each(function () {
    // do something
});

When I only loop through one of the two it does work.

3
  • The problem was that :select doesn't work, by changing it to select it worked both in my way as Box9's and michelgotta's way. Thanks Commented Mar 31, 2011 at 12:00
  • Using :input will give you all form elements like radiobuttons, checkboxes, textareas, inputs. There is no :select selector in jQuery. Commented Mar 31, 2011 at 12:01
  • And another thing learned today, thanks for the help! Commented Mar 31, 2011 at 12:05

3 Answers 3

7

The selector should be:

'#blockProperties :input, #blockProperties select'

What you have is looking for a select inside an input.

Sign up to request clarification or add additional context in comments.

Comments

5

The manual says :input "selects all input, textarea, select and button elements." So just do:

$('#blockProperties :input').each(function () {
    ...

Comments

2
$('#blockProperties input, #blockProperties select').each(function () {
    // do something
});

or (for all form elements):

$('#blockProperties :input').each(function () {
    // do something
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.