I have a form with different html input fields...
1) <input type="text">
2) <textarea></textarea>
3) <input type="checkbox">
4) <input type="radio">
5) <select></select>
How would I be able to determine what type of input field it is using jQuery. For example: If I wanted to do a check to see if input = "select" then do stuff.
$('input') // selects all types of inputs
$('input:checkbox') // selects checkboxes
$('select') // selects select element
$('input:radio') // selects radio inputs
$('input[type="text"]') // selects text inputs
you can use event.target.type
, this alerts what type of input
, textrea
or select
is the target of the event.
$('input, textarea, select').change(function(event){
alert(event.target.type)
})
http://jsfiddle.net/Q4BNH/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With