-2

I have link with below properties (class and title only) on my webpage :

<li class="wux-layouts-treeview-label" title="Shared with me">Shared with me</li>

I am trying below code for link in Javascript:

var a = document.getElementsByClassName("wux-layouts-treeview-label")[2];
a.click()

result shows undefined.

also when I checked events available for this link with the code :

getEventListeners(a), it shows blank {}

Please help me to click on this link.

Akhil Aravind
  • 5,741
  • 16
  • 35
Gitanjali
  • 9
  • 1
  • 3
    Possible duplicate of [How can I trigger a JavaScript event click](https://stackoverflow.com/questions/2381572/how-can-i-trigger-a-javascript-event-click) – 31piy Jul 18 '18 at 05:55
  • Add `console.log(a)` and check to make sure it returns an element. Can you show us some more of your code as well? – Lachlan Walls Jul 18 '18 at 06:04
  • @Lanchan Walls: I am getting value of "a" as
  • Shared with me
  • , but when I use a.click() -> it shows "undefined" – Gitanjali Jul 18 '18 at 06:08
  • Have you added an event listener to that element? If so, what should run when it is clicked? – Lachlan Walls Jul 18 '18 at 06:09
  • Yes i tried to add the "click" event using the code a.addEventListener("click",function(e){e.preventDefualt();console.log('clicked')}). Correct me in case. – Gitanjali Jul 18 '18 at 06:22
  • Try: `
  • Shared with me
  • ` and that should definitely output. – Lachlan Walls Jul 18 '18 at 06:32
  • Unfortunately, it didn't work. Still getting output as "clicked" and then "undefined". The output was as below : a.onclick() clicked undefined – Gitanjali Jul 18 '18 at 07:48