Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Placing an img element after an input tag w/ id

    In my first foray into DOM scripting, I need a little assistance. I'm attempting to place an img element after an input tag (which has an id).

    Code:
    var loadingImg = document.createElement('img');
    loadingImg.setAttribute('id', 'workimg');
    loadingImg.src = '/new/images/working.gif';
    document.getElementById('username').appendChild(loadingImg);
    Basically it's temporary feedback to tell the user that their request is "working". I'm not quite sure how to place the image element after the username element however. Ideas?
    "$question = ( to() ) ? be() : ~be();"

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    I'm attempting to place an img element after an input tag (which has an id).
    Use insertBefore() method and nextSibling target instead of appendChild

    PHP Code:
    ...
    var 
    loadingImg document.createElement('img');
    loadingImg.setAttribute('id''workimg');
    loadingImg.setAttribute('src''/new/images/working.gif');
    var 
    myInp document.getElementById('inputid');//your input element
    myInp.parentNode.insertBefore(loadingImg,myInp.nextSibling);
    ... 
    Last edited by Kor; 11-25-2005 at 11:04 AM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Aha! Thank you very much for your help, it is appreciated.
    "$question = ( to() ) ? be() : ~be();"


  •  

    Posting Permissions

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