【发布时间】:2014-10-07 13:00:50
【问题描述】:
当我单击一个按钮时,我试图将一个类切换到我的一个 div 上,由于某种原因,该类将被添加到 div 中,但实际的 CSS 属性不会发生。我正在尝试运行的功能位于底部。
这是我的代码:
HTML
<div class="mainPage">
<form class="homeButton" action="">
<input type="submit" value="Click to see who has had a worse day!">
</form>
</div>
<div class="textBox">
<h3>On (fill date), this person had a really terrible day.</h3>
<div class="badEvent">
<p>
</p>
</div>
<button>Close</button>
</div>
CSS
.mainPage {
background-color: #043D5D;
color: white;
text-align: center;
position: relative;
top: 0px;
left: 0px;
right: 0px;
h2 {
font-size: 4em;
}
p {
font-size: 2em;
}
form {
padding-bottom: 20px;
input {
width: 350px;
height: 50px;
border-radius: 10px;
font-size: .95em;
border: 1px solid #EB5055;
background-color: #EB5055;
cursor: pointer;
}
}
}
.replace {
background-color: red;
}
JS
$(".homeButton").on("click", function(event){
event.preventDefault();
$(".textBox").toggleClass('.replace');
});
【问题讨论】:
-
你能提供你的 html 标记吗?
-
抱歉,我添加了一个发布问题的问题。现在应该有 html 标记 @bencripps。
-
一方面,您需要将事件作为
argument添加到您的匿名函数中。
标签: javascript jquery css sass