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
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
Share Improve this question asked Jul 10, 2013 at 14:20 Anwar KortiAnwar Korti 1932 gold badges3 silver badges10 bronze badges 5- Your browser support getElementByClassName ? : developer.mozilla/en-US/docs/Web/API/… – d.danailov Commented Jul 10, 2013 at 14:23
- 1 With pure javascript i don´t think this works, you have to something mentioned here. Or just use jQuery. – luk2302 Commented Jul 10, 2013 at 14:23
- I use the chrome console – Anwar Korti Commented Jul 10, 2013 at 14:26
- 1 Your example works fine for me – musefan Commented Jul 10, 2013 at 14:27
-
Please show an example with some HTML. The
click()
method is supposed to return undefined so that's not out of the ordinary. Also, see: developer.mozilla/en-US/docs/Web/API/HTMLElement.click – Eddie Flores Commented Jul 10, 2013 at 14:31
1 Answer
Reset to default 1so
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)
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745673642a4639554.html
评论列表(0条)