[英]Event listener responds to first click, but does not execute .addClass() until second click
http://jsfiddle.net/gsqd4k5h/1/ http://jsfiddle.net/gsqd4k5h/1/
When I click on the event listener (#bar) the console.log fires but the.addClass() doesn't.当我单击事件侦听器(#bar)时,console.log 会触发,但 .addClass() 不会。 I looked through some threads on the topic but found nothing that helped.
我浏览了有关该主题的一些主题,但没有发现任何帮助。
HTML HTML
<div id="bar">
<div>
<div>
<span> This a reveal button </span>
</div>
</div>
<div class="hidden-section">
<div>
This is a bunch of hidden content
</div>
</div>
</div>
CSS CSS
#bar {
overflow-y: clip;
height: 48px;
transition: height 1s;
position: absolute;
z-index: 1005;
background-color: rgb(248, 249, 250);
border: 1px solid rgb(222, 226, 230);
border-radius: 5px;
}
.bar-open {
height: 365px !important;
}
.hidden-section {
padding-top: 100px;
}
JS JS
$("#bar").on('click', function(event) {
console.log("click")
$("#bar").addClass("bar-open");
});
Maybe like this:也许是这样的:
$("#bar").on('click', function(event) { console.log("click") $(this).addClass("bar-open"); console.log($(this).attr('class')); });
#bar { overflow-y: clip; height: 48px; transition: height 1s; position: absolute; z-index: 1005; background-color: rgb(248, 249, 250); border: 1px solid rgb(222, 226, 230); border-radius: 5px; }.bar-open { height: 365px;important. }:hidden-section { padding-top; 100px; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="bar"> <div> <div> <span> This a reveal button </span> </div> </div> <div class="hidden-section"> <div> This is a bunch of hidden content </div> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.