I have the following code in my external JS file:
var myDiv = $(".myDiv");
if (myDiv.css('left') == 'auto') {
var pos = myDiv.position();
myDiv.css({ "left:" + pos.left + "px", "top:" + pos.top + "px" });
}
It appears that the following line breaks my page:
myDiv.css({ "left:" + pos.left + "px", "top:" + pos.top + "px" });
If I comment it out everything works fine, except this functionality, obviously.
And if I put the values in alert I get them correctly as well.
alert(pos.left + ' ' + pos.top)
What am I missing?
You are trying to create an
objectby passing in 2strings.Should probably look like this: