$('#button').click(function() {
alert($('.column').val());
});
How could I get the first, second, or third element in .column?
$('#button').click(function() {
alert($('.column').eq(0).val()); // first element
alert($('.column').eq(1).val()); // second
alert($('.column').eq(2).val()); // third
});
I like selector strings, so I usually do this:
$('.column:eq(3)') // Fourth .column element
Use the Slice() function: http://api.jquery.com/slice/
See question: How to select a range of elements in jQuery
$('.column').slice(0, 2).each(function() {
$(this).val(); /* my value */
});
You could use the :lt (less-than) selector and tell it you want 0, 1, and 2 by indicating all .column elements below index 3:
$("#button").on("click", function(){
$(".column:lt(3)").each(function(){
alert( this.value );
});
});
.column, or three elements within a parent.columnelement?