SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jan 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Writing an img src value client side

    Hi folks

    Managed to get stuck over something that should be very simple.

    I'm wanting to write the src attribute of an img tag on the client-side.

    Doctype is XHTML 1.0 Transitional

    In the head, I'm loading a js function that generates the src path. I want to call it and have it re-write the src in an img element with a specific id.

    Can't waste any more time on this - suggestions very welcome.

    Sorry to ask something so basic - must be overlooking something.

    Thanks!

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    document.getElementById('myImgId').src = url;
    The dom node must exist before you can retrieve the id. So you need to wait until the page loads before changing it.

  3. #3
    SitePoint Member
    Join Date
    Jan 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks crmalibu - I'd forgotten about waiting till after the page load. (I only write JS once in a blue moon - or that's my excuse anyway...)


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
  •