Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

document.getElementbyID vs. variable declaration and delete performance

I would like to know what is more appropriate to do if I really need a good performance for my app. I'm programming cross-platform apps via PhoneGap and the way I code is very crucial.

Which is more appropriate:

document.getElementbyID('id').addEventListener()

or

var id = document.getElementbyID('id');
id.addEventListener();

and how can I use the keyword "delete" to improve the performance of my app?

like image 832
AJ Naidas Avatar asked Aug 25 '26 06:08

AJ Naidas


1 Answers

According to this test i just made on jsperf.com, document.getElementbyID('id').addEventListener() seems to be the fastest way. - in Chrome on Mac OS X.

Try it on the desired browsers, and edit the test to add/remove features such as the delete you were talking about.

JSPerf test results

like image 176
Pierre Avatar answered Aug 27 '26 19:08

Pierre



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!