After getting an element like this
$('.votes > a > img').get(0)
I am unable to call closest('img') on it. For example
$('.votes > a > img').get(0).closest('img')
I get an error saying there’s no method called ‘closest’.
But the following WILL work
$('.votes > a > img').closest('img') // removed .get(0)
Can someone please explain why this is?
I really don’t understand especially when I comare it to this on jsfiddle. In the jsfiddle version there’s a call to ('li.item-a').closest('ul').css('background-color', 'red'); which to me seems the same as my $('.votes > a > img').get(0).closest('img')
Replace
getwitheq, see the updated jsfiddle:Basically,
eqreturns a jQuery object that you can reuse, butgetgives you a DOM element, which is not jQuery and will not allow you to callclosestor other jQuery methods on it. See this SOq where you have more answers regarding thegetvs.eqdifference: