如何使用JQuery隐藏和显示HTML元素?

Rol*_*and 5 jquery

如何在没有任何特效的情况下使用JQuery隐藏和显示HTML元素?

cle*_*tus 13

使用hide()show()方法:

$("selector").hide();
$("selector").show();
Run Code Online (Sandbox Code Playgroud)

"选择器"是适当的.喜欢:

<script type="text/javascript">
$(function() {
  $("#mybutton").click(function() {
    $("#mydiv").toggle();
  });
});
</script>
<div id="mydiv">
This is some text
</div>
<input type="button" id="mybutton" value="Toggle Div">
Run Code Online (Sandbox Code Playgroud)

如果隐藏或者不隐藏,该toggle()方法只会调用.show()hide()


kar*_*m79 7

$('#someElement').show(); //an element with id of someElement

$('.someElement').hide();  //hide elements with class of someElement

$('a').hide(); //hide all anchor elements on the page
Run Code Online (Sandbox Code Playgroud)

看到:

http://docs.jquery.com/Effects/show

http://docs.jquery.com/Effects/hide

另外,阅读选择器是个好主意:

http://docs.jquery.com/Selectors