Which is faster: $("#element")[0].value
or $("#element").val()
? If the former is faster, what is the purpose of the latter?
$("#element")[0].value
is faster, native code is always faster.
Even faster would be document.getElementById("element").value
.
The .val()
function is to work for all input types, including <textarea>
and <select>
elements. Underneath, for everything that's not an <option>
or a <select>
or a <input type="radio">
(in some cases) it gets the .value
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With