MrFies
-
Posts
4 -
Joined
-
Last visited
Content Type
Profiles
Forums
Events
Posts posted by MrFies
-
-
Hi, I create a div and a button during runtime and try to center them.
darken.appendChild(message);darken.appendChild(errbtn);document.body.appendChild(darken);hcenter(message);hcenter(errbtn);
darken is another div, in which i put the massage und the button. Its all about error-handling.With hcenter I try to center both elements.
function hcenter(element){ var parent = element.parentNode; var pWidth = getwidth(parent); var eWidth = getwidth(element); var x = (Math.round(pWidth/2))-(Math.round(eWidth/2)); element.style.left = x+'px';}
With the first element it works without problem, but not for the button. I already had a look, if the button has no style.left but it seems to have. I alerted x and got the correct value for both elements.Has someone an idea?
-
thank you for answering, suddenly it works Oo - strange
-
Hello, I didnt find something about that. Normally there is explained to get an Object with
var MyElement = document.getElementById("MyDiv");
But now I have the Object from an Event-Handler and I want to get the id. I tried
var myid = MyElement.id; //result should be "MyDiv"
Can someone give me a hint?
Strange behaviour while positioning elements
in JavaScript
Posted
I found it myself. But my own post helped me out ;)I forgot the 'position: absolute;' in styles.css for the 'errbtn'