both ways are correct. but $("select").change(function() { alert( $(this).val() ); }); looks better. .val() is function built to take advantage over .attr('value'); its always good achieve same result by with less typing. As jQuery itsef says .. "Write Less Do More". :)
Ninad On Oct 13, 3:05 pm, James <james.gp....@gmail.com> wrote: > val() was built to have several advantages over attr("value") for form > fields. > For example, if your select element was one that allows you to select > multiple options, using: > attr("value") > (or just the basic 'value' attribute for that matter) > it will only get the first selected value. You'd have to manually loop > through the options to get the selected options. It was meant to work > almost exactly like the JS core 'value' attribute. > But if you use: > val() > you would get an array of all the selected values. It's built for you > already in jQuery. > > If you only have a select element that allows one selection, then it > probably doesn't matter much. Either one should work correctly in > most, if not all, browsers. > > On Oct 13, 11:24 am, Evgeny Bobovik <bobo...@gmail.com> wrote: > > > Why not?? I think that this method is most correctly from all:) > > Gk___ > > > 2009/10/13 MorningZ <morni...@gmail.com>: > > > > why not just use > > > > $("select").change(function() { > > > alert( $(this).val() ); > > > }); > > > > On Oct 13, 11:06 am, Evgeny Bobovik <bobo...@gmail.com> wrote: > > >> fist and second methods are correct? but this: > > >> $("select").change(function() { > > > >> alert($(this).attr("value")); > > > >> }); > > >> method will worked correctly in all browsers! > > >> Gk___ > > > >> 2009/10/13 Mike <mgor...@gmail.com>: > > > >> > $("select").change(function() { > > > >> > alert($(this).attr("value")); > > > >> > });