2

I have an array of element id's and would like to check for the type of element for further processing. My test for select, text, hidden and password work fine but not for radio. Here is roughly what I use for each.

if($('#elemID').is('select')) then do stuff...  this works.
if($('#elemID').is('input:text')) then do stuff...  this works.
if($('#elemID').is('input:hidden')) then do stuff...  this works.
if($('#elemID').is('input:password')) then do stuff...  this works.

if($('#elemID').is('input:radio')) then do stuff...  this does **NOT** work.

Any ideas on how to successfully test the element with element ID of elemID for a radio button would be greatly appreciated.

sdleihssirhc
  • 42,000
  • 6
  • 53
  • 67
Chris O
  • 689
  • 8
  • 22

3 Answers3

0

You can simply check the type attribute, like this:

var type = $('#elemID').attr('type'); //type will be either "hidden", "text", "radio", etc.
wsanville
  • 37,158
  • 8
  • 76
  • 101
0

It does work. Which version of jQuery are you using, and what does your markup look like?

karim79
  • 339,989
  • 67
  • 413
  • 406
0

One equivalent way of doing this is

if($('#elemID').is('input[type=radio]'))

Maybe that will work better. If it doesn't work I would like to see your array with elements