...

View Full Version : Placing an img element after an input tag w/ id



Velox Letum
11-25-2005, 07:53 AM
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).


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?

Kor
11-25-2005, 12:01 PM
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



...
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);
...

Velox Letum
11-25-2005, 05:21 PM
Aha! Thank you very much for your help, it is appreciated. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum