The below code uses this.value to get the value of a forms dropdowns. I have only generally seen .val() used. Is the below way acceptable cross-browser (especially older verions of IE)? Thanks!
$(':input', '#all').each(function() {
alert(this.value);
});
Yes, it’s acceptable, is more readable, and is less expensive (faster) than calling
$(this).val().Simply put,
$(this)refers to a jQuery object, whilstthisrefers to a DOM element.The FAQ here touches upon it briefly (under ‘Know Your DOM Properties and Functions’)
I’d also suggest reading the following:
$(this) vs this in jQuery
jQuery: What's the difference between '$(this)' and 'this'?
When to use Vanilla JavaScript vs. jQuery?
utilizing-the-awesome-power-of-jquery-to-access-properties-of-an-element
this demystified