Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS jQuery Basics (2014) Creating a Password Confirmation Form Perform: Part 1

Dave Osburn
Dave Osburn
7,558 Points

Is there a rule of thumb or best practice that dictates whether you should use jQuery or CSS to hide or show?

I've seen both used throughout this jQuery course and was wondering if there is a rule of thumb that dictates this decision. Whether you use hide() or some kind of event listener to toggle the CSS display:none attribute. Thanks!

1 Answer

Hi Dave,

These methods are pretty similar but they have some differences.

CSS display property is faster than JQuery's Hide/Show. Likewise when usiing JQuery's Hide/Show the value of the display property is saved in jQuery's data cache so that display can later be restored to its initial value.

You would want to use JQuery's Show/Hide when you are trying to add interactivity to your website like a mouse click.

You would want to use CSS display property for styling purposes (Usually hiding something when the webpage first loads)