Following is the form with id msform
that I want to apply style=\"display:none\" attribute to.
Please try below code for it :
$('#msform').fadeOut(50);
$('#msform').fadeIn(50);
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();
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.
$(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()
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');