hyperlink - Javascript click() return undefined - Stack Overflow

I try to simulate click on a link with javascripthere is the code:document.getElementsByClassName('

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
Add a ment  | 

1 Answer 1

Reset to default 1

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)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745673642a4639554.html

相关推荐

  • hyperlink - Javascript click() return undefined - Stack Overflow

    I try to simulate click on a link with javascripthere is the code:document.getElementsByClassName('

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信