Reputation: 9415
I'm trying implement a cancel feature so that if the user makes edits and clicks the "cancel" button, the page will revert to the original text.
Right now, I have the following javascript:
(function($) {
originalStepOrder = $('#org');
});
$(document).ready(function(){
$('.reorderCancel').click(function(){
$('#org').replaceWith(originalStepOrder);
console.log($('#org')==originalStepOrder);
});
}
However, when I click on the reorderCancel button, it get "false" in the console, and my "org" div is not replaced with its original contents. How can I fix this?
Upvotes: 0
Views: 47
Reputation:
That variable assignment is just pointing the variable to the object. When the object changes, the value of the variable is changing with it. You're going to need to make an actual copy. You can do that using .clone()
:
originalStepOrder = $('#org').clone();
For equality testing on jQuery objects, you should use .is()
:
$('#org').is(originalStepOrder);
Upvotes: 1