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;
}

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.