JQuery: Pro Tip Toggle Visibility

I’ve been coding with JQuery for a very long time, so I can’t believe I didn’t know this…

When I wanted to show/hide elements I would always use .is(:visible) and show or hide the object accordingly.

Yesterday, while looking for something else I found .toggle.

So:



$(this).toggle();

//will show or hide an element

I imagine a lot of you are thinking, “Well yeah…”

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s