I have tags <span>in divs that are deleted when the user clicks on them. It works great.
I want to save .text()inside this div in a variable. The problem is that the updated text is not saved.
Click on a word to remove it in jsFiddle .
As you can see, the variable contentreturns the old text, not the new changed one.
How to save a variable with updated text?
JQuery
jQuery(document).ready(function() {
jQuery(document).on("mousedown", ".hello span", function() {
var endChars = [".", "?", "!"];
jQuery(this).fadeOut(function(){
var parentObj = jQuery(this).parent();
jQuery(this).remove();
var text = parentObj.find("span").first().html();
parentObj.find("span").first().html(ta_capitalizeFirstLetter(text));
text = parentObj.find("span").last().html();
if ( endChars.indexOf(text.slice(-1)) == -1 )
{
parentObj.find("span").last().html(text+".");
}
});
var content = jQuery(this).parent().parent().find('.hello').text();
alert(content);
});
});
source
share