How can set the offset using JavaScript ?
+1
A:
You set the left
and top
CSS values.
With jQuery
$("#myEl").css({"position":"absolute","left":"100px","top":"100px"});
Straight Javascript
document.getElementById("myEl").style.position = "absolute";
document.getElementById("myEl").style.left = "100px";
document.getElementById("myEl").style.top = "100px";
Jonathan Sampson
2009-12-23 07:30:46
He said JavaScript, not jQuery.
drlouie - louierd
2009-12-23 09:31:50
You may want to read the tags again for this question, Louie. And besides, that's why I provided both Javascript and jQuery.
Jonathan Sampson
2009-12-23 13:34:55
A:
You could also add a class, e.g.
Jquery: $("p:last").addClass("selected");
Javascript: Someone has posted a JS function here - http://bytes.com/topic/javascript/answers/542128-can-javascript-add-new-style-class
You would then need to make sure that 'selected' was defined in your style sheet. The relevant CSS properties are:
top left margin padding
You probably want a combination of margin (offset outside element) and padding (offset inside element).
Aaron Newton
2009-12-23 07:45:41