Search code examples
javascriptpositionmootools

What is more correct "setPosition" or "style.left/right"?


I am trying to make a mootools drag on a iFrame.

Qestion:

Is it more correct to use

var div = parent.document.getElementById("price_info");
div.setPosition({ x: e.clientX-offX });

OR

var div = parent.document.getElementById("price_info");
div.style.left = (e.clientX-offX) + 'px';

This info will hopefully help me fixing a bigger problem... (here)


Solution

  • It comes down to the same thing. setPosition() writes to the element's style object, just like you would do manually.

    I suppose if you've taken the decision to build your code in a framework you should use its API where possible, unless there is a specific reason to ignore it and use vanilla JS in its place.

    Also, setPosition() returns the element(s) affected, whereas .style does not, so this may be a factor with regard to chaining, for example.