When I want to hide a HTML <div>
, I use the following JavaScript code:
var div = document.getElementById('myDiv'); div.style.visibility = "hidden"; div.style.display = "none";
What is the equivalent of that code in jQuery?
The hidden attribute hides the <div> element. You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid. A hidden <div> element is not visible, but it maintains its position on the page.
To hide a div using JavaScript, get reference to the div element, and assign value of "none" to the element. style. display property.
jQuery hide() Method The hide() method hides the selected elements. Tip: This is similar to the CSS property display:none. Note: Hidden elements will not be displayed at all (no longer affects the layout of the page). Tip: To show hidden elements, look at the show() method.
You must toggle it with a boolean true or false . . attr("hidden", false) will remove the attribute the same as using . removeAttr("hidden") .
$('#myDiv').hide();
or
$('#myDiv').slideUp();
or
$('#myDiv').fadeOut();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With