参考:评论发表@AnkithAmtange
鉴于html
<div>Click Away</div>
Run Code Online (Sandbox Code Playgroud)
CSS
div {
width: 200px;
height: 200px;
background: orange;
}
div:active {
color: white;
background: rebeccapurple;
}
Run Code Online (Sandbox Code Playgroud)
jsfiddle https://jsfiddle.net/u3uhq9m1/
如何将当前的:active伪类DOM元素传递给javascript?
第一次尝试.注意,jQuery不是必需的.
$(document).ready(function() {
var active;
$("div").click(function() {
active = $(":active");
setTimeout(function() {
console.log("active", active)
}, 1000)
})
})
Run Code Online (Sandbox Code Playgroud)