JQuery $(this).attr("name") vs this.name

Sameera Thilakasiri picture Sameera Thilakasiri · Apr 17, 2014 · Viewed 34.5k times · Source

What is the main different between

$(this).attr("name")

and

this.name

and What is the technical explanation?

Answer

Rory McCrossan picture Rory McCrossan · Apr 17, 2014

The first gets the attribute value from the jQuery object formed from the DOM element. The second gets the property directly from the DOM element, and is therefore quicker. You should use native properties where possible.