Codechef4u is a community for computer professionals,by computer professionals,just like you; who loves sharing and helping each others,Join them
Share your post

Reusable jQuery function to show or hide element

With following code sample, you can show or hide element by element id.

  • Pass following parameter to function
  • A Boolean flag, true for show and false for hide element
  • Your html element unique id

Code example

function showHideHtmlElement(toShow,elementId) {
    if (toShow) {
        if ($(elementId).is(":hidden")) {
            $(elementId).show();
        }
    }
    else {
        if ($(elementId).is(":visible")) {
            $(elementId).hide();
        }
    }
}
 

Invalid entry,please enter valid data.

Loading