The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Jquery to change background color of div on hover?

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #30881

    Hi, I’ve been Googling a bit but haven’t found a simple answer and must carry on with other tasks now (Boss breathing down my neck :) ) so if anyone has a simple routine or link to a routine to make a divs background color change on mouse over and then change back to the original color on mouse out I’d be grateful if they could post it here for me to grab and use later. Thanks very much. Cross browser compatible, ideally.


    Here is a link that will do what you are asking. What you need to do is create a class that has the background color you want, of course you can always animate this as well.

    Chris Coyier
    $("div").hover(function() { // mouseenter
    }, function() { // mouseleave

    You CAN alter CSS directly with jQuery with the .css() method, but as @ozee said, adding CSS classes is far more flexible (and faster, and… hotter).

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.