开发者

accessing element attributes with jquery vs. plain javascript, which is faster?

Which is faster: $(开发者_StackOverflow中文版"#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.


the same as $("#element") being slower than document.getElementById('element');

ease of use, consistency in the framework, hiding of cross-browser implementation (inconsistencies, not in the particular example but that is the concept of frameworks)..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜