How can I find out if an input field is anything other than a select
?
I tried with if($(el).not("select"))
and I get the selects too...
To check if the input text box is empty using jQuery, you can use the . val() method. It returns the value of a form element and undefined on an empty collection.
jQuery selectors are used to "find" (or select) HTML elements based on their name, id, classes, types, attributes, values of attributes and much more. It's based on the existing CSS Selectors, and in addition, it has some own custom selectors. All selectors in jQuery start with the dollar sign and parentheses: $().
Use the tagName property to check if an element is a select dropdown, e.g. if (select. tagName === 'SELECT') {} . The tagName property returns the tag name of the element on which it was accessed. Note that the property returns tag names of DOM elements in uppercase.
version added: 1.7jQuery. The $. isNumeric() method checks whether its argument represents a numeric value. If so, it returns true . Otherwise it returns false .
if(!$(el).is("select")) { // the input field is not a select }
$(el).not("select")
gives you array. Array is always gives true in boolean expressions. But after you apply not, this array of elements won't contain selects. See working example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With