Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript click() return undefined

I try to simulate click on a link with javascript

here is the code:

document.getElementsByClassName('link-a')[2].click();

When i try this

document.getElementsByClassName('link-a')[2];

I have the link that ai want to simulate a click but when i add the click() function it's return undefined and there is no click at all...

can you help me please?

Thank you for your help

like image 404
Anwar Korti Avatar asked May 01 '26 04:05

Anwar Korti


1 Answers

so

document.getElementsByClassName('link-a')[2];

gives you back an HTML element.

and you can call "click()" on it, because click is a method it provides.

click does return undefined (as expected)

like image 116
Zo72 Avatar answered May 02 '26 16:05

Zo72



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!