I have 3 divs, each with a dfew input fields and next button on.
I want to write a snippet of jQuery that when the next button is clicked it checks to ensure all input fields WITHIN the same div as the button, are not null.
I’ve tried the following with no luck but Im 100% certain its wrong, only I cant find the relevant information online…
You could use
filterto reduce the set of allinputelements to only those that are empty, and check thelengthproperty of what remains:Note that the definition of empty in the above code is an empty string. If you want to treat blank spaces as empty too, you may want to trim the value before comparing.
Also note that there is no need to pass
thisinto jQuery inside thefilterfunction. The DOM element itself will have avalueproperty, and it’s much faster to access that instead of usingval.Here’s an updated fiddle.