I have a page with elements, with relative position.
style="position: relative;"
Some have top/left coordinates and some don’t. Is there a way to check of the coordinates exist inside the style tag with jQuery?
If not, I’d like to add them by doing something like:
if (...) {
var myDiv = $(".myDiv");
var pos = myDiv.position();
myDiv.css({ "left:" + pos.left + "px", "top:" + pos.top + "px" });
}
As demonstrated by this jsfiddle the default value of top/left is “auto“. So to check if the CSS value is set or not, you can check whether the value is “auto” or not.
The test: