What is the performance difference between binding an onclick event through jQuery (1) and binding an onclick event through an HTML tag attribute (2)?
-
// Method 1 $('#element').click(function() { // code }); -vs- <!-- Method 2 --> <div class="x" id="element" onclick="handler();"></div>
-
Answer:
The performance difference, if there is one, is negligibly small compared to the cost of tightly coupling your markup and behavior. Unless you have an extremely good reason, [1] keep the Javascript away from your HTML and attach handlers with jQuery or the native methods. Well-abstracted, maintainable code is almost always worth a few extra function calls. ---- [1] You don't.
Bulat Bochkariov at Quora Visit the source
Related Q & A:
- What is the performance of INNER JOIN vs WHERE?Best solution by Stack Overflow
- What kind of performance chip should I use for a mercury cougar?Best solution by Yahoo! Answers
- What will be the difference in sound If I were to power my subwoofers with 2 ohms instead of 4 ohms?Best solution by Yahoo! Answers
- What is the sound difference between 2 ohms and 4 ohms?Best solution by Yahoo! Answers
- What is best performance for my 04 Mustang GT?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.