好吧,基本上我想做的是切换p元素的颜色,但是如果条件始终为false,就好了:
Html:
<p id="brand-element-Samsung" onclick="itemSelectedSamsung()" style="color: #ff0000">Samsung</p>
Sass:
p
width: 50%
margin: 25px 23px 20px 23px
padding: 15px 15px 15px 15px
cursor: pointer
&:hover
color: #a3abb1
transition: color .2s ease
Js:
function itemSelectedSamsung() {
var inactiveColor = "#ff0000"
var activeColor = "#2c3e50"
var hoveredColor = "#a3abb1"
var text = document.getElementById('brand-element-Samsung')
text.style.transition = "all .2s ease"
text.style.color === activeColor ? text.style.color = inactiveColor : text.style.color = activeColor
}