Skip to content Skip to sidebar Skip to footer

Uncaught Typeerror: Cannot Call Method 'replace' Of Undefined

$(this).find('input[name=amount]').val($(this).find('input[name=amount]').val().replace('$', '')); Keep getting this error on my developer tools. I just want to replace the charac

Solution 1:

Your error just says that there is no element that matches your selector, so element.val() is returning undefined, which has no replace method. Try debugging it and console.log() at each step.

Also, you don't need to search for the element twice. Just store it in a variable:

var $input = $(this).find('input[name="amount"]');
$input.val($input.val().replace('$', ''));

Post a Comment for "Uncaught Typeerror: Cannot Call Method 'replace' Of Undefined"