您好,我试图通过点击按钮切换div的类但似乎无法正常工作,有什么建议吗?
HTML
<img id="downarrow" src="images/downarrow.svg"/>
<div class="responsive-subscribe">
</div>
CSS
.responsive-subscribe {
position: relative;
width: 100%;
height: auto;
background-color: ;
bottom: 10px;
display: none;
}
.open {
display: block;
}
JAVASCRIPT
$(document).ready(function() {
$downarrow = $('#downarrow');
$downarrow.click(function() {
$(this).toggleClass('active');
$('.responsive-subscribe').toggleClass('.open');
});
});
答案 0 :(得分:2)
$('.responsive-subscribe').toggleClass('.open');
应该像$('.responsive-subscribe').toggleClass('open');
从.
.toggleClass('.open');
<强> Working Fiddle 强>
答案 1 :(得分:0)
你有一个小错字,删除&#39;。&#39;来自.toggleClass:
JS
$(document).ready(function() {
$downarrow = $('#downarrow');
$downarrow.click(function() {
$(this).toggleClass('active');
$('.responsive-subscribe').toggleClass('open');
});
});