Reputation: 1643
I'm missing something very basic here, I think!
$(function() {
$('#zahlungsart_0').click(function() {
var gesamtsumme_neu = Number($('#gesamtsumme').attr('rel'))+6;
gesamtsumme_neu.toString;
gesamtsumme_neu.replace('.',',');
console.log(gesamtsumme_neu);
$('#gesamtsumme').text(gesamtsumme_neu);
});
Error: TypeError: gesamtsumme_neu.replace is not a function
Thanks in advance for any help!
Upvotes: 1
Views: 58
Reputation: 5565
toString
is not a property, it's a function - toString()
, thus should be called as such. You're also not changing the value of the variable you call it on - you need to assign the return value to [another] variable:
$(function() {
$('#zahlungsart_0').click(function() {
var gesamtsumme_neu = Number($('#gesamtsumme').attr('rel'))+6;
var newVal = gesamtsumme_neu.toString().replace('.',',')
console.log(newVal );
$('#gesamtsumme').text(newVal);
});
Upvotes: 0
Reputation: 725
toString() returns a string, so try this:
var q = gesamtsumme_neu.toString();
q = q.replace('.',',');
console.log(q);
// etc
Upvotes: 1
Reputation: 20128
You have to call toString
and reassign it to the variable; just like you have to do with replace. Like this:
$(function() {
$('#zahlungsart_0').click(function() {
var gesamtsumme_neu = Number($('#gesamtsumme').attr('rel'))+6;
gesamtsumme_neu = gesamtsumme_neu.toString();
gesamtsumme_neu = gesamtsumme_neu.replace('.',',');
console.log(gesamtsumme_neu);
$('#gesamtsumme').text(gesamtsumme_neu);
});
The two function don't change the variable you are calling them on but return a new variable.
Upvotes: 1
Reputation: 10764
$(function() {
$('#zahlungsart_0').click(function() {
var gesamtsumme_neu = Number($('#gesamtsumme').attr('rel'))+6;
gesamtsumme_neu = gesamtsumme_neu.toString();
gesamtsumme_neu = gesamtsumme_neu.replace('.',',');
console.log(gesamtsumme_neu);
$('#gesamtsumme').text(gesamtsumme_neu);
});
Assign the values of toString(), replace() Also toString is a function
Upvotes: 1