+ 2

CSS JavaScript If Statement

How do I put an if statement in CSS? How does style work?

18th Jan 2018, 3:02 AM
YoBoi
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.
18th Jan 2018, 3:28 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 1
How?
18th Jan 2018, 3:29 AM
YoBoi
+ 1
var selected = document.getElementById("anID"); if (selected.style.background == "green"){ selected.style.background = "red"; }
18th Jan 2018, 6:23 AM
Jonas Schröter
Jonas Schröter - avatar
+ 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>
19th Jan 2018, 7:24 AM
Vinicius Souza
Vinicius Souza - avatar