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
Post a Comment