Get input of different types in a class using jQuery

Say I have a jquery function in JavaScript, and so far I have this code that works fine:

jQuery('div[class="someClass"] input[type="text"]').each( function() { //some code} . . .

In the above code, how can I target multiple types of inputs like textArea dropdown, etc. I am new to jQuery, so I don’t know about the format in which the Google search query didn’t make anything relevant! Please, help.

+3
source share
3 answers

If you are happy to select all the children of these types:

  • input
  • textarea
  • select
  • button

you can use the selector :input.

jQuery('div.someClass :input').each(function() {...

, , Niklas. , , . , :

jQuery('div.someClass').find('input[type="text"], select, textarea').each(function(){...

, , .

+8

:

jQuery('div[class="someClass"] input[type="text"], div[class="someClass"] textarea, div[class="someClass"] select').each( function() { //some code}
+3

Try the following:

jQuery('div[class="someClass"] :input').each(function(){
  //Do Something..
})

to avoid try button elements:

jQuery('div[class="someClass"] :input:not(:button)').each(function(){
  //Do Something..
})
+1
source

All Articles