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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Apr 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Internet Explorer problem moving dynamically created objects

    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.
    Code:
    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);
    }

  • #2
    New Coder
    Join Date
    Feb 2006
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry I wrote in the wrong forum? Delete this if you can
    Last edited by sherbert99; 04-28-2006 at 10:03 PM.

  • #3
    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
    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";
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #4
    New to the CF scene
    Join Date
    Apr 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Kor
    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?

  • #5
    New to the CF scene
    Join Date
    Apr 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

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