Access element attributes with jquery versus plain javascript, which is faster?

Which is faster: $("#element")[0].value or $("#element").val() ? If the former is faster, what is the purpose of the latter?

+4
source share
2 answers

$("#element")[0].value faster, native code is always faster.

document.getElementById("element").value will be even faster.

The .val() function should work for all input types, including the <textarea> and <select> elements. Under all of this, not <option> or a <select> or a <input type="radio"> (in some cases) receives .value .

+10
source

matches $("#element") slower than document.getElementById('element');

ease of use, consistency in structure, hiding cross-browser implementation (inconsistencies, not a concrete example, but this is the concept of frameworks).

+1
source

All Articles