Need to change an image href rollover effect into a td onclick

421 views Asked by At

I am not an experienced javascript, css coder so I would appreciate as much help as possible. I've read some other posts for more understanding; they mentioned jquery but I'm not sure how to go about that either.

I have a code that was generated for me with a program. I need to change about 7 image buttons (not links) href rollovers into td onclick. Thanks so much in advance. Here is my current code:

Within the head -

<script type="text/javascript">
function newImage(arg) {
if (document.images) {
    rslt = new Image();
    rslt.src = arg;
    return rslt;}
}

function changeImages() {
if (document.images && (preloadFlag == true)) {
    for (var i=0; i<changeImages.arguments.length; i+=2) {
        document[changeImages.arguments[i]].src = changeImages.arguments[i+1];}
}

}

var preloadFlag = false;
function preloadImages() {
if (document.images) {
    info_savantgenius_com_over = newImage("images/[email protected]");
    About_over = newImage("images/About-over.gif");
    Artist_over = newImage("images/Artist-over.gif");
    Portfolio_over = newImage("images/Portfolio-over.gif");
    Pricing_over = newImage("images/Pricing-over.gif");
    Order_over = newImage("images/Order-over.gif");
    Contact_over = newImage("images/Contact-over.gif");
    About_over033 = newImage("images/About-over-33.gif");
    Artist_over035 = newImage("images/Artist-over-35.gif");
    Portfolio_over037 = newImage("images/Portfolio-over-37.gif");
    Pricing_over039 = newImage("images/Pricing-over-39.gif");
    Order_over041 = newImage("images/Order-over-41.gif");
    Contact_over043 = newImage("images/Contact-over-43.gif");
    preloadFlag = true;}

}


Within the body -

<td colspan="2">

<a href="mailto:[email protected]"
            onmouseover="changeImages('info_savantgenius_com', 'images/[email protected]'); return true;"
            onmouseout="changeImages('info_savantgenius_com', 'images/[email protected]'); return true;"
            onmousedown="changeImages('info_savantgenius_com', 'images/[email protected]'); return true;"
            onmouseup="changeImages('info_savantgenius_com', 'images/[email protected]'); return true;">
            <img name="info_savantgenius_com" src="images/[email protected]" width="220" height="49" border="0" alt=""></a></td>
2

There are 2 answers

2
GregM On

You could use this :

http://api.jquery.com/hover/

So it would give you something like that :

$("#mytd1").hover(function(){$(this).css("background-image", [PUT THE NEW IMAGE PATH HERE])});

[PUT THE NEW IMAGE PATH HERE] something like that "url('image.jpg')"

And you need to include the jquery library

2
Pavel Podlipensky On

You can simply use document.getElementById() instead of document[changeImages.arguments[i]]

function changeImages() {
    if (document.images && (preloadFlag == true)) {
      for (var i=0; i < arguments.length; i+=2) {
        document.getElementById(arguments[i]).src = arguments[i+1];
      }
    }
}