Cover Image for jQuery hide() method
94 views

jQuery hide() method

The jQuery hide() method is used to hide selected elements. It allows you to conceal elements on a web page without any animation.

The syntax for using the hide() method is as follows:

$(selector).hide();
  • selector: It is a string that specifies the elements to be selected.

Here’s an example of how you can use the hide() method:

HTML:

<div id="myDiv">
  <p>This is some visible content.</p>
</div>
<button id="hideButton">Hide Content</button>

JavaScript:

// Attach a click event handler to the button
$('#hideButton').click(function() {
  // Hide the div
  $('#myDiv').hide();
});

In the example, when the button with the ID “hideButton” is clicked, the hide() method is used to hide the div element with the ID “myDiv”.

The hide() method sets the CSS property display to “none”, effectively hiding the element from the page layout. The element will still exist in the DOM, but it won’t be visible on the web page.

The hide() method is commonly used when you want to hide elements, such as sections, pop-up windows, or notifications, without any animation. If you want to hide elements with a fading animation, you can use the fadeOut() method instead.

If you need to show the hidden elements again, you can use the show() method to make them visible once more.

Overall, the hide() method provides a quick and straightforward way to hide elements on a web page, enhancing the user experience and allowing for dynamic content manipulation.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS