DavidRT49 DavidRT49 - 1 year ago 41
Node.js Question

Print on the console the link's name

i have an HTML list with some link:

<li><a href="#" name="link1">link1</a></li>
<li><a href="#" name="link2">link2</a></li>
<li><a href="#" name="link3">link3</a></li>

Each link has a different name.

In nodeJS, when i click the link i want to print on the console the name of the link that I clicked.

how can i do?

Answer Source

You can use this javascript code to print the name of the link

  <li><a href="#" id="link1" name="link1" onclick ="console.log('link1')">link1</li>
  <li><a href="#" name="link2" onclick ="console.log('link2')">link2</li>
  <li><a href="#" name="link3" onclick ="console.log('link3')">link3</li>