Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery loop through input and select fields

Tags:

jquery

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.

like image 347
Mats Hofman Avatar asked Oct 17 '25 15:10

Mats Hofman


2 Answers

The selector should be:

'#blockProperties :input, #blockProperties select'

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

like image 89
David Tang Avatar answered Oct 20 '25 06:10

David Tang


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

$('#blockProperties :input').each(function () {
    ...
like image 24
karim79 Avatar answered Oct 20 '25 05:10

karim79



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!