jQuery $.each() not saving changes
by elgreg
HTML
<span id="source"></span><br /><br />
<button onclick="doReplace()"
title="Replace all change with done">
Replace
</button><br /><br />
<span id="result"></span>
CSS
span { color: Blue; }
JavaScript
//basic custom object with two properties
var obj = {
testA: {'message': "please change this"},
testB: {'message': "and change this too"}
};
//display original text
$(document).ready(function() {
$("#source").text("Source: " + obj.testA.message + " + " + obj.testB.message);
});
//search/replace properties and display result
function doReplace() {
$.each(obj, function (index, value) {
console.log(this);
console.log(index);
console.log(value);
var newVal = value['message'].replace("change", "done");
console.log(newVal);
this['message'] = newVal;
//value = newVal;
});
$("#result").text("Result: " + obj.testA.message + " + " + obj.testB.message);
}