Jump to content

[SOLVED] How to set top, left of div dynamically?


sayedsohail

Recommended Posts

Hi everyone,

 

I am having problem dynamically setting up the position showstatusdiv on the fly.

 

I wish to set the top and left when i called showstatusdiv function.

 

Here is the code: 

 

function showstatusdiv(boxcontents) {
    hidestatusdiv();
    z=document.body.appendChild(document.createElement("div"));
    z.id = "statusbox";
    z.style.position = "absolute";	
    if (self.pageYOffset != null) {	
z.style.top = self.pageYOffset + "px";	
    } else if (document.documentElement.scrollTop != null) {
z.style.top = document.documentElement.scrollTop + "px";	
    }
    z.style.width = "50%";
    z.style.left = "0px";
    z.style.background = "#ffffff";
    z.style.border = ".3em solid #ff0000";
    z.style.padding = ".3em 1.3em .3em .3em";
    z.style.zIndex = "1000";

    z.innerHTML = '<div style="position: absolute; border: 1px solid black; top: 0px; right: 0px;"><span style="padding: .3em; font-weight: bold;"><a style="text-decoration: none;" title="Close status box" href="#" onclick="javascript:hidestatusdiv();">X</a></span></div>';
    z.innerHTML += boxcontents;
}

Link to comment
Share on other sites

Can you please correct the code where i made mistakes, your help is greatly appreciated.  As i am not that good with javascript.

 

What exactly i want is to provide left and top, right margins when i called the function

 

showstatusdiv("Test","200px","100px", "200px")
i.e., margin-left 200px 
i.e., margin-top 100px
i.e., margin-right 200px

Thanks

Link to comment
Share on other sites

oh, you want to pass parameters to the function and have them define the top and the left attributes?

 

if so,

 

function showstatusdiv(content, top, left){

...

z.style.left = left;

z.style.top = top;

...}

 

is that what you're looking for?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.