Let’s say a form has 5 ‘text’ inputs and 3 ‘radio’ inputs. If the user clicks on one of the ‘radio’ inputs, how can I find the index of that input among inputs of the same type? In other words, if the user clicked on the second of the three radio inputs, I’m looking for the result 2.
I’ve tried the following in jQuery:
$("input").click(function(event) {
alert( $("input").index(event.target) );
}
That’s close but it returns the index among ALL input results, not just the input type that was clicked on.
NOTE: I don’t know what the input type will be before the event is triggered so I’m asking how to narrow down the selector based on the clicked input type.
Try