jQuery $.each() not saving changes
by alano
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: "please change this",
testB: "and change this too"
};
//display original text
$(document).ready(function() {
$("#source").text("Source: " + obj.testA + " + " + obj.testB);
});
//search/replace properties and display result
function doReplace() {
$.each(obj, function (index, value) {
var newVal = value.replace("change", "done");
this[index] = newVal;
//value = newVal;
});
$("#result").text("Result: " + obj.testA + " + " + obj.testB);
}