Wednesday, August 15, 2012

Setting coordinate/positioning using Javascript

If you ever set positioning in javascript using syntax similar to below and didn't work (in browser standard mode):

var some_div = document.getElementById("some_div");
some_div.style.top  = "30";
some_div.style.left = "30";

What missing is only the unit of measurement when setting top and left position.

var some_div = document.getElementById("some_div");
some_div.style.top  = "30" + "px";
some_div.style.left = "30" + "px";