Which is faster: $("#element")[0].value or $("#element").val()? If the former is faster, what is the purpose of the latter?
Which is faster: $(#element)[0].value or $(#element).val() ? If the former is faster, what is
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
$("#element")[0].valueis 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.