JQuery how to find the last child

For those who know jQuery, it takes less effort - I would like to get an element that is a last child of another element (of type "input", which I know its identifier ("myID").
What is the correct query: I tried:

$("input:last-child", $("#myID")); 
 $("#myID input:last-child") 

But it didn’t work

+3
source share
2 answers

Try:

$("#myID input:last") //for the last

$("#myID input:first") //for the first
+7
source

You can also use the latter method. Something like that:

$("#myID").last();  

But make sure you have jquery 1.4.X. If : the latter matches only one element,: the last-child can match more than one: one for each parent.

and I think that what you write will work this way.

$("#myID input:last-child").val();
0
source

Source: https://habr.com/ru/post/1785860/


All Articles