在默认情况下切换单击隐藏

时间:2015-02-13 08:36:19

标签: jquery

我使用jQuery切换来隐藏点击div。 但是我想默认隐藏div。 我该如何解决这个问题?

我使用此代码:

$('.fold_reply').click(function() {
    $('.reply').toggle(500)
})

http://jsfiddle.net/z9rGz/307/

2 个答案:

答案 0 :(得分:3)

添加css规则以将display设置为none

.reply{display: none;}

演示

jQuery.noConflict();
jQuery(function($){
  $('.fold_reply').click(function() {
    $('.reply').toggle(500)
  });
});
.reply {
  display: none
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="reply">
    Some content
    <br />
    Some more content
</div>

<button class="fold_reply">Fold</button>

答案 1 :(得分:0)

选项1:正如@Arun P Johny已经写道:添加css display : none;

Example

选项2:使用jquery隐藏div:$('.reply').hide();

Example

相关问题