SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict trinity0159's Avatar
    Join Date
    Jul 2002
    Location
    California
    Posts
    239
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Changing the link on an image

    I am trying to write a script that changes image 1 to image 2. I have figured this part out but now need to change the link that image 1 is pointing to say google.com and when image 2 is shown have the link change to yahoo.com

    How do I do this?

  2. #2
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    One solution: do it with divs:

    Code:
    <div id="imgDiv" style="position:absolute;visibility:visible">
    <a href="members.aol.com/grassblad"><img src="<A href='http://members.aol.com/grassblad/images/grassblade.gif">http://members.aol.com/grassblad/images/grassblade.gif"></a>
    </div>
    <script language="javascript">
    alert(document.links[0])
    if (document.layers)
    {
       document.layers['imgDiv'].open();
       document.layers['imgDiv'].write('<a href="<A href='http://www.javascriptcity.com">www.javascriptcity.com"><img src="someImg.gif"></a>')
       document.layers['imgDiv'].close();
       document.layers['imgDiv'].visibility = 'visible';
    }
    else if (document.all)
    {
       document.all['imgDiv'].innerHTML ='<a href="<A href='http://www.javascriptcity.com">www.javascriptcity.com"><img src="someImg.gif"></a>'
    document.all['imgDiv'].style.visibility = 'visible';
    }
    else
    {
       document.getElementById('imgDiv').innerHTML ='<a href="<A href='http://www.javascriptcity.com">www.javascriptcity.com"><img src="someImg.gif"></a>';
    document.getElementById('imgDiv').style.visibility = 'visible';
    }
    alert(document.links[0])
    </script>
    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  3. #3
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I think you can change it just with
    Code:
    document.getElementById("ImgId" ).href=""newhref
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •