Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - check if an input is not a select field

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...

like image 431
Alex Avatar asked Jan 31 '11 16:01

Alex


People also ask

How can check input value is empty or not in jQuery?

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.

Is Element Select jQuery?

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: $().

How do you know if an element is selected?

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.

How can check input value is number or not in jQuery?

version added: 1.7jQuery. The $. isNumeric() method checks whether its argument represents a numeric value. If so, it returns true . Otherwise it returns false .


2 Answers

if(!$(el).is("select")) {     // the input field is not a select } 
like image 148
Darin Dimitrov Avatar answered Sep 28 '22 00:09

Darin Dimitrov


$(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.

like image 27
gor Avatar answered Sep 28 '22 01:09

gor