Javascript: Automatically clicking a button?

▼魔方 西西 提交于 2019-12-10 13:15:34

问题


I'm learning how to write a chrome extension, and I'm fairly new to javascript.

Here's some html:

<div class="button data" style="">
   <a class="button1 whiteColor" href="http://link1.com">VIEW This</a>
   <a class="button2 redColor" href="http://link2.com">VIEW That</a>
</div>

What I want to do is open link2.com by automatically clicking button2 using javascript.

I'm using the following, but it's not working :/

document.getElementByClassName("button2 redColor").click();

Any help would be appreciated!!


回答1:


document.getElementsByClassName("button2 redColor")[0].click();

You need select index, because getElementsByClassName return the array



来源:https://stackoverflow.com/questions/17144459/javascript-automatically-clicking-a-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!