What does this jQuery mean?

   $("#element").get(0).value =  v;
+3
source share
2 answers

Get the first DOMElement that matches this query (similarly getElementById('element').value = v). Really bad jQuery style.

$("#element").val(v); could be used to make it more jQuery-ish and independent of input type.

+5
source

It is true that using your own properties available in DOM elements, instead of jQuery methods.

With get() (docs), you extract the DOM element from the jQuery object, and then valueset your new value using your own property .

The equivalent that I would prefer to use would be:

$("#element")[0].value =  v;

... that would do the exact same thing, but do it directly through the index of the DOM element.

+3
source

Source: https://habr.com/ru/post/1785917/


All Articles