jQuery: How to check id is shown or hidden

In many cases we do not want make two buttons to show or hide a same div area. for example expand and collspan method. jQuery provides a simple technique to check div id is already shown or hidden.

Create a div are on which you want to do operation:

Click on me
Content will be here!!!

Then make a function in the javascript in your head tag.

function __showHideFullDetail(divID) {
	if ( jQuery('#' + divID).is(':hidden') ) { 
		jQuery('#' + divID).show('slow');
	} else {
		jQuery('#' +divID).hide('slow');
	}
}

In this function we checked that provided div id is already shown or hidden. If it status is hidden then it will show it otherwise hide it.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

*