Using jQuery is there any benefit to using $(selector).get(0)
over $(selector)[0]
if I just want to get the first item in the jQuery array as a DOM ele
As an ardent fan of code readability by humans I suggest neither approach is satisfying. .get(0)
and [0]
look too much like container indexing. More is at stake when converting a jQuery object to a DOM object. So I introduce a function to name what's going on.
function dom_from_$($jquery_object) {
var dom_object = $jquery_object.get(0);
return dom_object;
}
Used like this:
var domElement = dom_from_$($(selector));