Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4015286
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:36:02+00:00 2026-05-20T09:36:02+00:00

I am try position a div using absolute positioning and it works fine in

  • 0

I am try position a div using absolute positioning and it works fine in Safari and Firefox but fails in IE and I can’t figure out why. The code is this:

var tempX=123;
var tempY=456;
var commentnum=3;
var bodyelement = document.getElementsByTagName('body')[0];
var newdiv = document.createElement('div');
newdiv.setAttribute('id', 'comment_text'+commentnum);
newdiv.setAttribute('style', 'text-align:center;z-index:10001;left:'+(tempX-23)+'px;top:'+(tempY-80)+'px;position:absolute;');
newdiv.innerHTML = commenthtml;
bodyelement.appendChild(newdiv);

The script is suppose to generate a div where the user clicks the mouse. But in IE it places the div to the left side and then stacks them on top of each other. Can anyone give me an idea why this is not working?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:36:03+00:00Added an answer on May 20, 2026 at 9:36 am

    According to quirksmode, setAttribute can not be used to set the style attribute in IE.

    http://www.quirksmode.org/bugreports/archives/2005/03/setAttribute_does_not_work_in_IE_when_used_with_th.html

    Using setAttribute, you should be able to set any attribute on an element. It appears that in IE, trying to set the style attribute does not work.

    Instead you may need to set the style properties individually:

    newdiv.style.textAlign = 'center';
    newdiv.style.zIndex = 10001;
    newdiv.style.left = (tempX-23) + 'px';
    newdiv.style.top = (tempY-80) + 'px';
    newdiv.style.position = 'absolute';
    

    EDIT:

    It appears as though IE has a cssText property. I’m not sure about browser support, but perhaps you could test for it.

    if( 'cssText' in newdiv.style ) {
        newdiv.style.cssText = 'text-align:center;z-index:10001;left:'+(tempX-23)+'px;top:'+(tempY-80)+'px;position:absolute;';
    } else {
        newdiv.setAttribute('style', 'text-align:center;z-index:10001;left:'+(tempX-23)+'px;top:'+(tempY-80)+'px;position:absolute;');
    }
    

    Tested cssText in Chrome 10 and Firefox 3.6, and it works.


    EDIT2:

    It appears as though there’s wide support for that property on elem.style, so you may just want to use it instead of setAttribute().

    newdiv.style.cssText = 'text-align:center;z-index:10001;left:'+(tempX-23)+'px;top:'+(tempY-80)+'px;position:absolute;';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having an issue positioning a div that I've styled using CSS in
I am trying to use jQuery to fade out a div, using the fadeOut
I'm using the ajax to load a div content, but the div content is
I try to move a specific div using jQuery animate . However, It does
I am using the following code to try and move a simple div element
i am using the jQueryUI Position Utilities, but i don't know why it not
When I try to compile this code: struct BasicVertexProperties { Vect3Df position; }; struct
Im getting a -1 value when i try to get the selected item position
Try as I might, I can't get a JNLP file to run locally (via
try it out: volatile float bob = -344.0f; unsigned int fred = (unsigned int)bob;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.