Jump to content
Sign in to follow this  
MrFies

Strange behaviour while positioning elements

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?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...