i have a button and some inputs, i want to let jquery check for me if none of the inputs is empty before doing some action : so this is what i’ve done :
$('#my_button)').click(function() {
if(
for(i=0;i<$('#my _button').parent().prev().children().children().length;i++){){ //this is to check if the inputs exist
$('#my_button').parent().prev().children().children().eq(i).val()!==''; // i've tried .val().is(:empty); but not working too
//so the test fails for somehow ! and the if condition doesn't work
// google chrome developers inspector gives me this error (Uncaught SyntaxError: Unexpected token for)
}
){
//do some action
}}
and this is my jsfiddl test !
It gives you the unexpected token warning on the
forbecause it is an unexpected token. You can’t putforloops in the boolean expression of an if statement.You will need to do something similar to this pseudo-code: