How can i change a class on mouseover?

Discussion in 'HTML & Website Design' started by leftwheel, Aug 18, 2009.

  1. #1
    Hi!

    I'm working on a wordpress template at the moment.

    http://janwei.startlogic.com/testblog/

    I have a purple rss icon in my footer that i want to change to a blue one on mouseover. I have defined the two icons in two seperate classes in my footer named rss-tag-icon and rss-tag-icon2.

    I have the following code in my footer:

    <a href="?feed=rss2"><img class="rss-tag-icon" onmouseover="changeclass='rss-tag-icon1';" onmouseout="this.className='rss-tag-icon';"

    What am i doing wrong here?
     
    leftwheel, Aug 18, 2009 IP
  2. Whizkid

    Whizkid Well-Known Member

    Messages:
    324
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    135
    #2
    Maybe a slightly simpler way of changing the icon is to only use CSS instead of using CSS+Javascript.

    Here's an example setup taken from your code:

    HTML:
    
    <a href="?feed=rss2"><img class="rss-tag-icon" width="35" height="35" /></a>
    
    Code (markup):
    CSS:
    
    #footer .rss-tag-icon {
    background-image:url(images/rssIcon.png);
    background-position:left bottom;
    background-repeat:no-repeat;
    float:left;
    height:35px;
    margin:7px 0 0 5px;
    position:relative;
    width:35px;
    }
    
    Code (markup):
    
    #footer .rss-tag-icon:hover {
    background-image:url(images/rssIcon2.png);
    }
    
    Code (markup):
    Since you are already loading the image through CSS already (and the link to your image in the html does not work anyway), using the hover pseudo-class makes a lot more sense.

    Note: No changes were made to #footer .rss-tag-icon
     
    Whizkid, Aug 19, 2009 IP
  3. leftwheel

    leftwheel Well-Known Member

    Messages:
    725
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    135
    #3
    I just did exactly what you said but it doesn't work. The rss icon now disappears on mouseover.

    By the way:
    How could you read out my CSS Code "footer rss-tag-icon"?
     
    Last edited: Aug 19, 2009
    leftwheel, Aug 19, 2009 IP