Answer: Use the jQuery css() Method You can use the jQuery css() method to change the CSS display property value to none or block or any other value. The css() method apply style rules directly to the elements i.e. inline.
jQuery attr() Method The attr() method sets or returns attributes and values of the selected elements. When this method is used to return the attribute value, it returns the value of the FIRST matched element.
display = "none"; To show an element, set the style display property to “block”.
Display:none; means the element will not be displayed, and Display:block; means the element is displayed as a block-level element (like paragraphs and headers).
Why not just use $('#msform').hide()
? Behind the scene jQuery's hide
and show
just set display: none
or display: block
.
hide()
will not change the style if already hidden.
based on the comment below, you are removing all style with removeAttr("style")
, in which case call hide()
immediately after that.
e.g.
$("#msform").removeAttr("style").hide();
The reverse of this is of course show()
as in
$("#msform").show();
Or, more interestingly, toggle()
, which effective flips between hide()
and show()
based on the current state.
As an alternative to hide()
mentioned in other answers, you can use css()
to set the display
value explicitly:
$("#msform").css("display","none")
$(document).ready(function(){
var display = $("#msform").css("display");
if(display!="none")
{
$("#msform").attr("style", "display:none");
}
});
You can use the hide
and show
functions of jquery. Examples
In your case just set $('#msform').hide()
or $('#msform').show()
Based on the comment we are removing one property from style attribute.
Here this was not affect, but when more property are used within the style it helpful.
$('#msform').css('display', '')
After this we use
$("#msform").show();
You can just use: $("#msform").hide()
. This sets the element to display: none
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