javascript - how to find the type is select or input in jquery -


this html:

<div id="demo">   <span><input type="text"></input></span>   <span><select>     <option value="test1">test1</option>     <option value="test2">test2</option>   </select></span> </div> 

this js:

if($(demo).find(nth-child(2)).is('select')) {   //something } 

i need check whether select or input type.kindly me!

your code works fine, need wrap selectors in quotes , include required prefixes. try this:

if ($('#demo').find(':nth-child(2)').is('select')) {     console.log('its select'); } 

example fiddle


Comments