Reputation: 6728
I'm trying to get all select elements in a given div, even though they have different class names. It looks like this:
<div id="mydiv">
<select class="myclass">...</select>
<select class="myotherclass">...</select>
</div>
I'd like to get all the selects with myclass
or myotherclass
. I've tried several ways but can't get it right.
I've tried variations of the following:
$.each($('[#mydiv select.myclass][#mydiv select.myotherclass]'), function(){ // handle stuff
$.each($('#mydiv select.myclass select.myotherclass'), function(){ // handle stuff
$.each($('#mydiv select.myclass myotherclass'), function(){ // handle stuff
and others, but I can't seem to get both selects into my element selection.
Upvotes: 1
Views: 117
Reputation: 2150
Try this
JS CODE
$('#mydiv select').each(function(){
console.log($(this));
});
Upvotes: 1
Reputation: 2317
I think it works with
$('#mydiv select.myclass, #mydiv select.myotherclass')
as in Css Selectors
Upvotes: 1
Reputation: 5225
$.each($("#mydiv .myclass, #mydiv .myotherclass"), function(){ // handle stuff });
Upvotes: 1
Reputation: 16505
Perhaps
$('#mydiv select.myclass, #mydiv select.myotherclass')
Upvotes: 7