SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Puzzled by Firefox re DOM script

    Can anyone explain why this (in a slideshow function) doesn't work in Firefox?
    Code:
    var newsrc=images[index]
     var placeholder=document.getElementById("Slideshow")
    placeholder.setAttribute("src",newsrc);
    but this does:
    Code:
    document.Slideshow.src = newsrc;
    I thought they should do the same thing. The first doesn't do anything. Both work in IE. I've put alerts in the function to check that it's being called properly and the variables are correct, and they are. I must have a syntax error but don't know what it is.

    The next line:
    Code:
    document.getElementById("Slideshow").setAttribute("alt", alts[index])
    works fine in both browsers. I can't point you to the page as it's on a corporate intranet.

  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    images[index].toString() converts the image to its src text (url) in IE,
    it returns 'HTMLimageObject' in firefox. You are coercing the string conversion when you use an object in setAttribute.

    images[index].src returns the src text in both browsers.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Aha. I was misguidedly thinking images[index].src was the 'old, deprecated' way of doing it and the DOM method was the new way. Now I've learned something.

    Thank you for taking the time to respond.

  4. #4
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was misguidedly thinking images[index].src was the 'old, deprecated' way of doing it
    You could always use
    document.getElementsByTagName('img')[index].getAttribute('src')

    But if you are using HTML (not xml) the property name and images array still work.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Useful tip, thanks.


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
  •