I was writing some code today and I wanted to prompt the user to check if they wanted to delete a row of data only if there was some data they might not want deleted. Typically to do this I would loop through all the input fields and if any of them weren’t blank I would run the check. I figured that there must be a better way with callbacks or selectors, and after a little thinking I wrote this jQuery snippet :
row.find('input[value!=""]').length > 0
This basically says count the number of inputs with a non-blank value you find, inside the given row.
Just like my last post, it’s nothing amazing but it sure is a better way of doing things. If you look into the andSelf() method then you could also easily chain selects and other input types.
I’m also interested if someone has a better way to approach this problem?
November 19th, 2008 at 9:27 pm #Tony
Cool idea.