To try and help you understand why it doesn't work, let's read your code:
- Find all
.money elements, and get the html of the first one.
- Replace the
. with a ,
- Find all
.money elements, and set their html to that first value.
Second code:
- Find all
.money elements, and get the html of the first one.
- Replace the
. with a ,
- Do bugger all.
This is one of the many problems I have with jQuery: ambiguous functions. .html() returns the HTML of the first element in the set, but .html(value) replaces the HTML of all elements in the set.
Anyway, the jQuery you're looking for is:
$(".money").each(function() {
var $this = $(this);
$this.html($this.html().replace(".",","));
});
Consider also this Vanilla JS:
[].forEach.call(document.querySelectorAll(".money"),function(e) {
e.innerHTML = e.innerHTML.replace(".",",");
});
While is may look like more or messier code, it is many many times faster than any jQuery solution.
And finally, a hybrid solution that combines performance with browser compatibility:
$(".money").each(function() {
this.firstChild.nodeValue = this.firstChild.nodeValue.replace(".",",");
});
Enjoy!