I have a div with this class :
.news{
width:710px;
float:left;
border-bottom:1px #000000 solid;
font-weight:bold;
display:none;
}
<
In JavaScript:
getElementById("id").style.display = null;
In jQuery:
$("#id").css("display","");
jQuery's .show() and .hide() functions are probably your best bet.
The only way to remove an inline "display:none" via jQuery's css-api is by resetting it with the empty string (null
does NOT work btw!!).
According to the jQuery docu this is the general way to "remove" a once set inline style property.
$("#mydiv").css("display","");
or
$("#mydiv").css({display:""});
should do the trick properly.
IMHO there is a method missing in jQuery that could be called "unhide" or "reveal" which instead of just setting another inline style property unsets the display value properly as described above. Or maybe hide()
should store the initial inline value and show()
should restore that...
Using show()
adds display:block
in place of display:hide
which might break things.
To avoid that, you can have a class with property display:none
and toggle that class for that element with toggleClass()
.
$("button").on('click', function(event){ $("div").toggleClass("hide"); });
.hide{
display:none;
}
div{
width:40px;
height:40px;
background:#000;
margin-bottom:20px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div></div>
<button>Toggle Box</button>
None of the answers mentioned this.
You're not giving us much information but in general this might be a solution:
$("div.news").css("display", "block");
To hide the div
$('.news').hide();
or
$('.news').css('display','none');
and to show the div
:
$('.news').show();
or
$('.news').css('display','block');