admin管理员组文章数量:1435859
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)
本文标签: hyperlinkJavascript click() return undefinedStack Overflow
版权声明:本文标题:hyperlink - Javascript click() return undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745673642a2669719.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论