Skip to content
Advertisement

Jquery not finding links

I have the following code with Jquery.

JavaScript

I don’t know why the first link <a> is not getting selected but the last one? Anything wrong in my code, any fix?

JavaScript
JavaScript

Advertisement

Answer

The issue is because by using find() you’re telling jQuery to look for the selector you provide within the parent element. As the parent itself is the a element, it obviously doesn’t find anything.

To fix this you can instead use filter():

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement