Monday, April 09, 2012

Now you see me… show/hide performance » Learning jQuery - Tips, Techniques, Tutorials

Now you see me… show/hide performance » Learning jQuery - Tips, Techniques, Tutorials: ".css({'display':'none'}) & .css({'display':'block'});
These methods were very snappy. They showed an improvement over .addClass() and .removeClass() in Opera and IE 6/7 and about the same in other browsers. They work great if you know the current display style of all the elements you are changing, or at least have not changed the display style inline. If you have changed the display style inline, then you will need to make sure you set the correct value when you make the element visible again. If you are just using the elements' default display value or set the display value in the css, then you can just remove the style like so, .css({'display':''}), and it will revert to whatever value it has in the css or by default. As a library, jQuery can't assume that the display element wasn't set inline, so it has to manually keep track of it. That is the main slowness you can avoid since you know you won't be setting the display inline."

'via Blog this'