error1

Problem with the second drag event

HTML

<script src="http://cachedcommons.org/cache/jquery-cookie/0.0.0/javascripts/jquery-cookie.js"></script>
<div id="draggable" class="ui-widget-content">Drag me around</div>

JavaScript

var lastPosition = JSON.parse(localStorage.getItem("lastPosition")) || JSON.parse($.cookie("lastPosition"))
if (lastPosition) {
    $("#draggable").css({
        "position": "absolute",
            "top": lastPosition.top,
            "left": lastPosition.left
    });
}
$("#draggable").draggable({
    stop: function (event, ui) {

        if (typeof localStorage)
            localStorage.setItem('lastPosition', JSON.stringify($(this).position()));
        else 
            $.cookie('lastPosition', JSON.stringify($(this).position()));

    }
});