I am having an issue with a script containing the lines below (top is commented out right now). They are in a loop to do a sum on the textboxes on a form. However, I get: 'Uncaught TypeError: Cannot read property '0' of undefined' when this runs. If I comment out the bottom line and uncomment the top line, it works fine.
I still want to keep the replace function though and I am not sure how to go about this.
total += $(this).text();
//difference and why the previous works, but the below returns null, but if
total += ($(this).all.value.replace(/\D/g, '')) * 1
.text() gets or sets the text inside an element.
console.log($('p').text()) will return
.value() isn't a jquery method, instead use .val()
.val() is used to get or set the value of an input field.
<input type="text"> If you wanted to get or set the value of the input, say on form submit, you would use something like