jquery - Using $.css() without selector increases performance? -


jquery allows use $.css() method directly , pass raw dom element first parameter. example, if want set 'a' width of mydiv, jquery allows syntax:

(option 1):

var elem = document.getelementbyid('mydiv'); var = $.css(elem, 'width'); 

instead of (option 2):

var = $('#mydiv').css('width'); 

option 1 not require selector, , appears rely on global jquery object instead of creating new one. can't find documentation in jquery api or online method. assume performance increase, when jquery objects required in animations. reason why shouldn't using method?

thanks!

edit: perf tests show option 1 bit faster. doesn't seem there's reason not use $.css() directly. answers!

yeah, first 1 faster. can css value.

i made perf test here: http://jsperf.com/jquery-css-signature may revise , test out other options.

now facts set, @ these level of performance optimisation, don't think worth overhead. go more clear/maintainable way of getting same result. performance benefit ain't big enough matters in case.


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -