I can’t seem to get the type property in jQuery 1.6
<div id="div_id">
<input type="text" value="foo" />
<input type="text" value="foo" />
<input type="text" value="foo" />
<input type="text" value="foo" />
<input type="checkbox" checked="checked" />
</div>
and jquery
$.each('#div_id input',function(index,value){
var input_type = $(this).prop('type')
alert(input_type);
/*
switch(input_type) {
case 'checkbox':
$(this).prop('checked',false);
break;
//more cases here
default:
this.value = '';
}*/
});
see my fiddle
This is because you’ve misunderstood the
$.each()function, which accepts an array or object (as opposed to a selector). When you pass a string to$.each(), jQuery iterates over all the characters in the string (in most browsers).To fix the issue you can pass the selector to jQuery and either use the result in
$.each(), or call.each()on the result:See your updated fiddle.
If you’re feeling bold, you can ditch jQuery inside the function and access the property directly, increasing efficiency and reducing code: