I would like to assign a cookie to a variable…
e.g.
var aVariable = $.cookie("moo");
I am using the jQuery cookie functions – do I need to set the cookie AND set the variable at the same time or something?
Help pretty please!
^.^
My Code:
function goBackToPosition() {
var xPos = $.cookie("yourPositionX");
var yPos = $.cookie("yourPositionY");
console.log(xPos);
console.log(yPos);
if (xPos) {
alert("xpos!");
$(this).animate({
top: yPos,
left: xPos
}, 400, function(){
$.cookie("yourPositionX", null);
$.cookie("yourPositionY", null);
});
}
}
I get the following error: a.ownerDocument is undefined
Your syntax is wrong here:
Perhaps you meant:
Or:
In response to your update / new issue:
$(this)will not work in the scope ofgoBackToPositionas this references that function, rather than an element. You will have to change$(this)to$('selector')to get it to work.Or use
goBackToPosition.call($('selector'))if you would like to keep using this.The call function alters the value of this when the called function executes, a similar function is
apply.