How to set offset in javascript

How to set offset using javascript?

+6
javascript jquery css
source share
2 answers

You set CSS values left and top .

With jQuery

 $("#myEl").css({"position":"absolute","left":"100px","top":"100px"}); 

Direct javascript

 document.getElementById("myEl").style.position = "absolute"; document.getElementById("myEl").style.left = "100px"; document.getElementById("myEl").style.top = "100px"; 
+12
source share

You can also add a class, for example.

Jquery: $ ("P: last"). AddClass ("selected");

JavaScript: Someone posted a JS function here - http://bytes.com/topic/javascript/answers/542128-can-javascript-add-new-style-class

Then you need to make sure that “selected” has been defined in your stylesheet. Corresponding CSS properties:

left upholstery box on top

You probably need a combination of field (offset of the outer element) and padding (offset within the element).

0
source share

All Articles