Search code examples
jqueryjquery-validateerrorplacement

How to target select box in jQuery validate errorPlacement?


If I had an input of type "radio", I would target it like this:

if (element.attr("type") == "radio")

How do you target a select box? I've tried:

if (element == "select")

but that doesn't work. I know it's got to be something simple, but I just don't know the syntax.


Solution

  • Since element refers to the whole object, you can't just compare it to select with a comparison operator ==.

    Simply use the .is() method for this...

    if ( element.is('select') ) { ....
    

    DEMO: http://jsfiddle.net/18xogtk3/