Good day. I used search but didn't find the answer I was looking for, I think this is a common question.
Is there any solution to get value of n-th element via jQuery?
Here is simple example:
Imagine that we have n inputs with same class. The easiest way to get value of n-th, as I thought $(".some_class").get(n-th).val()
the simplest way. But when we use get()
, it returns
Object #HTMLInputElement
So after using on it val()
we got error:
Uncaught TypeError: Object #HTMLInputElement has no method 'val'.
Is there any solution how use only jQuery methods in this situation?
Use eq
instead:
$(".some_class").eq(n-th).val()
eq
constructs a new jQuery object from the element you've specified within the set.
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