tags:

views:

36

answers:

4
A: 

You can't have multiple same id's! Also id cannot be number-starting. Add class like "c1", then

$('.main .select').each(function(el){
alert($(this).val());
});

I'm new to jQuery, so check

Misiur
+3  A: 

A valid HTML markup needs to have unique ids. So don't use multiple ID's. Use classes instead, lets assume you have a class called one assigned to multiple elements:

$('.one').each(function(){
    $(this).somefunction();
});

That code would query all those elements and call a method somefunction() on each of them.

See .each()

jAndy
+1 made your rep 10k ;)
Sinan Y.
@Sinan Y.: Wooho, Yay! ;)
jAndy
A: 

Misiur was close but the each method just takes a function with the index and element. Also I added the div tag before the classes so that it doesn't look at all elements. Just makes it a little more efficient.

$('div.main div.select').each(function(index, el){
    alert($(this).val());
});
Jeff T
if you dont use the arguments in the each callback function, you can leave them off and simply let `this` be the curent element in the loop. `('div.main div.select').each(function() { alert($(this).val()); });`
Squeegy
very true, i was just including it there for completeness because sometimes the index can be useful
Jeff T
A: 

You probably don't need numbers on each div.

$('.main div:nth-child(1)').each( myFunction );

function myFunction()
{
   //operate on $(this)
}
Stefan Kendall