markray markray - 1 year ago 40
jQuery Question

Get the Count of Input Tags inside a Div Element using the Closest Property Jquery

I know it is a stupid question but i couldn't find a solution for this. Knocking my head for hours.

I have a HTML Structure,

<div class= 'container'>
<div class="someclass">
<input>some content</input>
<input>some content</input>
<input id="question-xxx" type="hidden"></input>

I need to get the count of all the Input elements inside the class = 'someclass' using the id = "question-xxx".

I tried using




I googled it out, and I have no clue what I'm doing wrong. Any help would be quite appreciable.


.someclass will not be found using closest try finding it by siblings.

closest is used to find the parent element of given element. Here someclass is not parent of question-xxx.

closest and parent are same. You can find more info here