Reference: Comments posted by @AnkithAmtange
Given html
<div>Click Away</div>
css
div {
width: 200px;
height: 200px;
background: orange;
}
div:active {
color: white;
background: rebeccapurple;
}
jsfiddle https://jsfiddle.net/u3uhq9m1/
How to pass the currently :active
pseudo class DOM
element to javascript
?
First attempt. Note, jQuery is not a requirement.
$(document).ready(function() {
var active;
$("div").click(function() {
active = $(":active");
setTimeout(function() {
console.log("active", active)
}, 1000)
})
})
https://jsfiddle.net/u3uhq9m1/1/
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…