View Full Version : Getting attributes from css divs

06-14-2010, 04:34 PM
Hey there.

I want to move a div around a page, and I do this by getting the original top and left values of a div, and then change them.

But the problem is getting the original values; I checked online and thought that this would work:

var chart = document.getElementById(charDiv).style.top;
var charl = document.getElementById(charDiv).style.left;
alert('char_t:' + chart + ' char_l:' + charl + 'charDiv:' + charDiv);

charDiv is passed into the function (its the id of the div I want to move). I know that charDiv has a value by looking at the values of the alert() statement, but the values of chart and charl are empty. The alert simply outputs

char_t: char_l: charDiv: charOne

any help would be appreciated :)

06-14-2010, 05:52 PM
Try using the function given under "The script" at http://www.quirksmode.org/dom/getstyles.html