...

View Full Version : Internet Explorer problem moving dynamically created objects



karlkittler
04-28-2006, 10:00 PM
I'm working on a script where I need to move objects. The best way for me to create the objects is via document.createElement.

As to be expected, this works just find in FireFox, but Internet Explorer is being difficult.

I can create the element just fine. I can make it visible, invisible, but I can't move it.

Any ideas?

init() is called in the onLoad. 'slider' is in the HTML body.

function init(){ //set up display
createDiv('text0','Test Text','LINKHERE');
//alert(findWidth('text0')); //element can be found.
document.getElementById('text0').style.left = '100px'; //move to the right 100px
alert('moved'); //for some reason, the element does not move;
document.getElementById('text0').style.visibility = 'hidden'; //invisible
alert('invisible'); //we can make it invisible
document.getElementById('text0').style.visibility = 'visible'; //visible
alert('visible'); //and visible
document.getElementById('text0').style.left = '100px'; //move to the right 100px
alert('moved'); //but for some reason, the element does not move;
}

function createDiv(id,text,href){
var div=document.getElementById("slider");
var innerdiv=document.createElement("div");
//innerdiv.id = id;
innerdiv.setAttribute("id", id);
innerdiv.setAttribute("class", "text");
//innerdiv.setAttribute("style","position:relative;left:100;width:auto;"); //tried setting attribs, didn't make a difference.
innerdiv.style.left=100;
var linkElement = document.createElement("a");
linkElement.setAttribute("href", href);
var textElement = document.createTextNode(text);
linkElement.appendChild(textElement);
innerdiv.appendChild(linkElement);
div.appendChild(innerdiv);
}

sherbert99
04-28-2006, 10:59 PM
Sorry I wrote in the wrong forum? Delete this if you can

Kor
04-29-2006, 07:50 AM
IE uses className. But you may use DOM 0 crossbrowser syntax:
innerdiv.className="text";

On the other hand you should specify the measurement units and set as strings. Moz likes you to do so:

innerdiv.style.left="100px";

karlkittler
05-01-2006, 04:34 PM
IE uses className. But you may use DOM 0 crossbrowser syntax:
innerdiv.className="text";

On the other hand you should specify the measurement units and set as strings. Moz likes you to do so:

innerdiv.style.left="100px";

IE didn't like the innerdiv.className('text'); at all, but no relavent error was given.
innerdiv.setAttribute("style","position:relative;left:100px;width:auto;"); didn't make a difference.
Any other ideas?

karlkittler
05-02-2006, 10:38 PM
Solution is, after creating the object, even if you specify that it is an absolutely postioned object via element.setAttribute('style','position:absolute'); you have to specify after doing the last appentChild:
document.getElementByID('name').style.position = 'absolute';
In the above example, Line 3 would be the ideal place to do this.

And people wonder why I curse M$ under my breath.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum