How can i copy $(this).html() by value, NOT by reference?
Hi, i'm trying to copy the HTML-Content of an element to a variable, after that i want to change the HTML-Content of the element.
How do i copy by value? Default it seems to be copied by reference, i.e. i copy the html-content to a variable, then i change the html-content, and it is changed in the new variable as well.
Here's the code:
$(function(){
var editedTarget = null;
var currentTargetValue = 0;
$(".editable-target").click(function(){
editedTarget = $(this);
$(this).css("padding","0");
console.log($(this).html());
var currentTargetValue = parseInt($(this).html(),10);
console.log(currentTargetValue);
$(this).html('bla')
});
});
HTML-Content of .editableTarget is a number (e.g. 52).
On clicking .editableTarget console.log() outputs four lines (i expected two lines, but $(this).html('bla') seems to trigger the console.log()'s once more, god knows why):
52
52
bla
NaN
How can i write the .html()-Content of an element to a variable, without having the content of this variable altered when changing the .html()-Content afterwards?