开发者

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开发者_开发技巧...


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.


The .not() method returns a new jQuery object with everything from the original object that doesn't match the selector.
You can't just use it in an if statement like that.

Instead, you use the .is method, which checks whether the element matches a selector and returns a boolean.

if (!$(el).is('select'))


What about giving the <select> tags a class:

$(el + ":not('.select')")


if($(el).selectedIndex)

If it has a SelectedIndex property, it's a <SELECT>


if ($(el)[0].nodeName != 'select')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜