Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-25-2005, 06:53 AM   PM User | #1
Velox Letum
Senior Coder

 
Join Date: Apr 2005
Location: Colorado, United States
Posts: 1,208
Thanks: 0
Thanked 0 Times in 0 Posts
Velox Letum is an unknown quantity at this point
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();"
Velox Letum is offline   Reply With Quote
Old 11-25-2005, 11:01 AM   PM User | #2
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
Quote:
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);
... 
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

Last edited by Kor; 11-25-2005 at 11:04 AM..
Kor is offline   Reply With Quote
Old 11-25-2005, 04:21 PM   PM User | #3
Velox Letum
Senior Coder

 
Join Date: Apr 2005
Location: Colorado, United States
Posts: 1,208
Thanks: 0
Thanked 0 Times in 0 Posts
Velox Letum is an unknown quantity at this point
Aha! Thank you very much for your help, it is appreciated.
__________________
"$question = ( to() ) ? be() : ~be();"
Velox Letum is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:46 PM.


Advertisement
Log in to turn off these ads.