Jump to content

Strange behaviour while positioning elements


MrFies

Recommended Posts

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?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...