Skip to content
Advertisement

why am I getting text of all the links instead of one that is clicked by .text() function

When I click on the A1-810 or A1-820 Link.

Output Comes Like this

A1-810

ICONIA A-SERIES
A1-810
A1-820

Now the HTML Nav links are a little complicated actually there are more than 200 links in the navbar but I have copied a little code so that you can understand.

JavaScript
JavaScript

Advertisement

Answer

You attach the event listener to the LI instead of the A

The LI.text() will show all children of that LI

When you attach to the A instead the content of the clicked anchor is shown also use preventDefault so the link is not followed

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