I wan\'t to change the background color of a div dynamicly using the following HTML, CSS and javascript. HTML:
-
I prefer foxy's answer because we should never use javascript when existing css properties are made for the job.
Don't forget to add display: block ;
in .menuItem
, so height and width are taken into account.
edit : for better script/look&feel decoupling, if you ever need to change style through jQuery I'd define an additional css class and use $(...).addClass("myclass")
and $(...).removeClass("myclass")