I'd like to find out if an input is a checkbox or not, and the following doesn't work:
$("#myinput").attr('checked') === undefined
Thank you once again!
I'd like to find out if an input is a checkbox or not, and the following doesn't work:
$("#myinput").attr('checked') === undefined
Thank you once again!
>>> a=$("#communitymode")[0]
<input id="communitymode" type="checkbox" name="communitymode">
>>> a.type
"checkbox"
Or, more of the style of jQuery:
$("#myinput").attr('type') == 'checkbox'
You can use the pseudo-selector :checkbox
with a call to jQuery's is
function:
$('#myinput').is(':checkbox')
Use this function:
function is_checkbox(selector) {
var $result = $(selector);
return $result[0] && $result[0].type === 'checkbox';
};
Or this jquery plugin:
$.fn.is_checkbox = function () { return this.is(':checkbox'); };