How to find out the type of an object - is this a checkbox in jquery?

How to determine the type of object is a flag or something else.

+3
source share
4 answers

You can use the method is:

if ($(this).is(":checkbox")) {
    // is checkbox
} else {
    // not checkbox
}
+5
source

You can check its type attribute. Using jQuery:

if($('input').attr('type') == 'checkbox') {
   // do if checkbox
} else {
  // do if not checkbox
}
+1
source
$(element).attr('type') == 'checkbox'
+1
source

You can use:

$("input[type='checkbox']").whatever();
+1
source

All Articles