SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Jun 2004
    Location
    Montreal
    Posts
    275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Get image source inside a link

    I've got this :

    <a id="m0" href="#" title="Find Home Health Agencies"><img src="media/graphic/menu/agencies_s.png" alt="Find Home Health Agencies" /></a>

    How can I get the src of the image so I can swap it with an onmouseover?

    Also, why when I do some javascript in Firefox, sometime, the browser goes crazy like refresh does not work or I can access others tabs ??

    thank

  2. #2
    SitePoint Evangelist vikrantkorde's Avatar
    Join Date
    Jun 2004
    Location
    Mumbai, India
    Posts
    541
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey turb,

    there are 2 ways to do that.
    1) give the id to that image and then take an object of that image from document.getElementById("imgID"); then you can change its source by obj.src = "newImage.jpg";
    2) As you have already given the ID to anchor tag, get the object of that anchor, get the chidren from that obj.children(). as you know there is only one child, you can get the first element from the children array. then change the src of that.

    to invoke any of the above function you can add onmouseover="yourFunction();" in either anchor or in image tag.
    Vikrant Korde
    S Y S T I M E, Mhape,
    Mumbai, Maharashtra, India.

  3. #3
    SitePoint Addict
    Join Date
    Jun 2004
    Location
    Montreal
    Posts
    275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank alot! Will take a look!

    However, can someone explain me why when I try some javascript scripts, Firefox goes crazy? For example, sometime I can't access the refresh or back button of the browser, neither my bookmark in the Bookmark Toolbar???

    Somebody know why?

  4. #4
    Guru Meditation Error gnarly's Avatar
    Join Date
    Dec 2003
    Location
    Cheltenham, United Kingdom
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The most likely reason is that your code is going into an infinite loop. I'd reccommend that you install http://www.joehewitt.com/software/firebug/ and make use of it's debugger features to try and figure it out.
    Olly Hodgson
    thinkdrastic.net


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
  •