Skip to content
Advertisement

jQuery hover and class selector

I wan’t to change the background color of a div dynamicly using the following HTML, CSS and javascript. HTML:

JavaScript

CSS:

JavaScript

Javascript:

JavaScript

EDIT: I forgot to say that I had reasons not to want to use the css way.

And I indeed forgot to check if the DOM was loaded.

Advertisement

Answer

Your code looks fine to me.

Make sure the DOM is ready before your javascript is executed by using jQuery’s $(callback) function:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement