This returns an index based on the zero value of the selected radio book
$('input[name=compression]:checked').index()
In the case described in the use of the comment (which is usually the correct syntax to use)
$('input[name=porient]:checked').index('input[name=porient]')
If you want to know why the first of them gives incorrect results, you should read . index () documentation
If no argument is passed to .index (), the return value is an integer indicating the position of the first element in the jQuery object relative to its sibling elements.
In the sample of the question, there were no βotherβ brothers and sisters other than your ham radio. So it works.
In the example from the comment, the <br /> tag is a brother of radio objects and therefore is located at index 1. That's why you think index() giving the wrong position
jitter
source share