Skip to content
Advertisement

How can I get text of parent link while link is clicked

If I click on the link A1-810 I am getting text A1-810 in anchortext variable. Now I want is when I click on A1-810 I should also get text ICONIA A-SERIES in parenttext or another variable

if A1-810 link is clicked I am getting output as

A1-810

Now I want output as

A1-810

ICONIA A-SERIES

Jquery code to get the text of the link.

JavaScript

HTML CODE.

JavaScript

Advertisement

Answer

You can do it like this.

JavaScript

Use .closest("ul") to travel up to find the first ul.
Then use .prev("a") to get the previous sibling of the element type a(link).

Demo

JavaScript
JavaScript
Advertisement