Given the following sample code:
$(document).ready(function(){
$(":input").blur(function(){
alert("The input type is:" ); //How would this look??????
})
});
How can I detemine whether this is an input, select, text, etc?
This is not a real-world example but should suffice for the purposes of this question
Given the following sample code:
$(document).ready(function(){
$(":input").blur(function(){
alert("The input type is:" ); //How would this look??????
})
});
How can I detemine whether this is an input, select, text, etc?
This is not a real-world example but should suffice for the purposes of this question
Share Improve this question edited Feb 1, 2015 at 16:26 Deduplicator 45.7k7 gold badges72 silver badges123 bronze badges asked Dec 21, 2009 at 14:40 Mutation PersonMutation Person 30.5k18 gold badges100 silver badges165 bronze badges 05 Answers
Reset to default 11$(this).attr("type");
See jQuery's Selectors/Attribute documentation for additional information.
How can I deteminedetermine whether this is an input, select, text, etc?
Note that select
, textarea
, "etc" elements are not covered by $('input')
. You probably rather want to use $(':input')
to get them all.
$(document).ready(function(){
$(':input').blur(function(){
alert('The tag is:' + this.tagName);
if (this.tagName == 'INPUT') {
alert("The input type is:" + $(this).attr('type'));
}
})
});
$(this).attr("type");
for example:
$(document).ready(function(){
$("input").blur(function(){
alert("The input type is:" + $(this).attr("type"));
})
});
Why not go through and see what attribute/property would be most useful?
$(document).ready(function(){
$("input").blur(function(){
for (var x in this)
alert(x + ":" + this[x]);
})
});
This should work...
$(document).ready(function(){
$("input").blur(function(){
var type = this.type;
alert("The input type is:" + type);
})
});