开发者

how to change css style from jquery

开发者 https://www.devze.com 2022-12-08 03:57 出处:网络
my style is here #mybox{ di开发者_JAVA百科splay:none; } my web is here <div id=\'mybox\'> ... </div>

my style is here

#mybox{
di开发者_JAVA百科splay:none;
}

my web is here

<div id='mybox'>
...
</div>


<script type='text/javascript'>
  $(document).ready(function(){
   $("#mybox").css("display","visible");
})
</script>

mybox don't show. How to show mybox ?


use $("#mybox").show() or $("#mybox").css("display","block");


$('#mybox').show();

or

$('#mybox').slideDown();


It is display: block in stead of display visible:

<div id='mybox'>
...
</div>


<script type='text/javascript'>
  $(document).ready(function(){
   $("#mybox").css("display","block");
})
</script>


If you use the CSS with display:none; on an element you can trigger .show() and .hide() with jQuery on it! This is a jQuery default feature.


Firstly, "visible" isn't a valid value for the display attribute. Something like "block" or "inline" is. Secondly, don't set CSS directly like this. It's problematic. Instead use the jQuery effects for showing and hiding things (show/hide/toggle, slideUp/slideDown, fadeIn/fadeOut, etc):

$(function() {
  $("#mybox").show();
});

or alternatively use a class:

$(function() {
  $("#mybox").toggleClass("visible");
});

with:

div.visible { display: block; }
0

精彩评论

暂无评论...
验证码 换一张
取 消