Ask coding questions

← Back to all posts
Why use Javascript instead of CSS For rollovers
AIC27 (0)

###If you are making a very simple rollover, should you use javascript instead of CSS? this code



seems a lot easier to me than

var button1 = document.getElementById("button1")
function rollover(){ = red

function rollback(){ = blue

button1.onmouseover = rollover
button1.onmouseout = rollback

if a rollover is this simple, should I just use CSS instead of JS?

Answered by EpicGamer007 (1735) [earned 5 cycles]
View Answer
AIC27 (0)
EpicGamer007 (1735)

always use css, never use js for setting up animations/css. if you want to change the color(or change anything style-wise) of a div or button, always use css unless it is absolutely necesary to use javascript

also, the tutorials section is for posting tutorials, for questions, you post to the ask board.

AIC27 (0)

@EpicGamer007 oops. Didn't realize I had.

Bookie0 (6259)

CSS was invented for styling webpages. JS is to make it interactive. Also, it isn't easier as first of all the CSS looks a bit more intuitive/easier to use than the JS code, and second of all there are less lines in the CSS.

xxpertHacker (930)

JS will over-complicate everything, just use HTML and CSS, if you even need CSS, that is.