Is JavaScript style.display = "none" or is jQuery.hide () more efficient?

document.getElementById("elementId").style.display="none" 

used in JavaScript to hide an element. But in jQuery

 $("#elementId").hide(); 

used for the same purpose. Which method is more effective? I saw a comparison of the two jQuery functions .hide() and .css("display","none") here .

But my problem is, is pure JavaScript more efficient than jQuery?

+43
performance javascript jquery css
Dec 03
source share
4 answers

Speaking of efficiency:

 document.getElementById( 'elemtId' ).style.display = 'none'; 



What jQuery does with its .show() and .hide() methods is that it remembers the last state of the element. Sometimes this can come in handy, but since you asked about efficiency that doesn't matter here.

+78
Dec 03
source share

Efficiency will not matter for something like that in 99.999999% of situations. Do whatever is easier to read and maintain.

In my applications, I usually rely on classes to provide hiding and showing, for example .addClass('isHidden')/.removeClass('isHidden') , which would allow me to animate things with CSS3 if I wanted to. This provides more flexibility.

+24
Dec 03
source share
 a = 2; 

against

 a(2); function a(nb) { lot; of = cross; browser(); return handling(nb); } 

In your opinion, what do you think will be the fastest?

+19
Dec 03 '12 at 17:14
source share

Yes.

Yes it is.

Vanilla JS is always more efficient.

+9
Dec 03
source share



All Articles