Following is the form with id msform
that I want to apply style="display:none" attribute to.
<form id="msform" style="display:none;">
</form>
Also the check should be performed before adding the "style=display:none;"
property. That is if it is already set like in above code it should not set again.
But if it's not set then it should.
How should I achieve this? Please help me.
This question is related to
javascript
jquery
html
css
show-hide
Please try below code for it :
$('#msform').fadeOut(50);
$('#msform').fadeIn(50);
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 use the jquery attr() method to achieve the setting of teh attribute and the method removeAttr() to delete the attribute for your element msform As seen in the code
$('#msform').attr('style', 'display:none;');
$('#msform').removeAttr('style');
$(document).ready(function(){
var display = $("#msform").css("display");
if(display!="none")
{
$("#msform").attr("style", "display:none");
}
});
As an alternative to hide()
mentioned in other answers, you can use css()
to set the display
value explicitly:
$("#msform").css("display","none")
You can just use: $("#msform").hide()
. This sets the element to display: none
Source: Stackoverflow.com