+ 2
CSS JavaScript If Statement
How do I put an if statement in CSS? How does style work?
4 Respuestas
+ 3
You can't put if statements in CSS because it's not a programming language. But you can use JavaScript to manipulate CSS.
+ 1
How?
+ 1
var selected = document.getElementById("anID");
if (selected.style.background == "green"){
selected.style.background = "red";
}
+ 1
<!DOCTYPE html>
<html>
<body>
<h2>What Can JavaScript Do?</h2>
<p id="demo">JavaScript can change the style of an HTML element.</p>
<button type="button" onclick="document.getElementById('demo').style.fontSize='35px'">Click Me!</button>
</body>
</html>