Trying to add a class to a button if there has been any input in one of six text fields on the page. Getting a console error that says “Uncaught TypeError: Object [object Object] has no method 'value'” referring to my var val line.
Syntaxual? Thanks for your help.
HTML:
<input id="a" class="answer" type="text">
<input id="b" class="answer" type="text">
JavaScript:
var val = $('.answer').each(function(){
$(this).value();
});
if (/^\s*$/.test(val)){
$('#theOne').addClass('show');
}
The method is
val, notvalue:You may have been thinking of the native
valueproperty (which is probably preferable in terms of efficiency):However, none of this helps seeing as your
eachloop doesn’t actually do anything. You could usefilterto see if any of your inputs have a value: