55493

Javascript: Automatically clicking a button?

Question:

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!!

Answer1:

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

You need select index, because getElementsByClassName return the array

Recommend

  • Embedded Jetty does not find Annotated Servlet
  • How can I implement Borrow for a generic container in the case of the use of associated types?
  • How to replace certain rows by shared column values in pandas DataFrame?
  • TypeScript keyof returning specific type
  • Function which returns multiple values
  • DoEvents is used yet application is not responsive
  • WebProxy on Portable Class Library
  • Access VBA lookup folder and create if does not exist DLOOKUP
  • Sharing multiple images on facebook post
  • How to use CoreFoundation in QuickTime SDK for Windows?
  • jqGrid Filter Toolbar and Date and Select filters
  • Google Apps Script fails to generate image from EmbeddedChartBuilder
  • Network communication options in Java (Client/Server)
  • mssql script data insert or update
  • Questions related to Garbage Collector and finalize() method
  • Align microsoft access queries
  • can you use embedded ruby in custom javascript files in rails?
  • Scripting Support For Image Filtering in DigitalMicrograph
  • Pandas time series data Index from a string to float [duplicate]
  • JavaMail connection problems [duplicate]
  • how to specify different css for ie
  • How can i move Clearcase dyamic/snapshot views to another host (Linux)
  • Multiplying polynomials/simplifying like terms
  • Rotating Towards Path in OpenGL
  • How to split wav file into two or more parts using c#
  • Floating parent div grows to hypothetical width of floating child div
  • Content-Type alternative in MQTT
  • How to use Streams api peek() function and make it work?
  • Send array to next viewcontroller iOs xcode [duplicate]
  • php “page caching” solution suggestions for CMS Applications
  • How to encrypt Connectionstring written in web.config from codebehind?
  • Codeigniniter insert data through models and controller
  • Call Microservice from another Microservice within Docker
  • Jersey serializes character value to ASCII equivalent numeric string
  • PHP Permalinks.. how to change?
  • media foundation H264 decoder not working properly
  • CAS 4 - Not able to retrieve the LDAP groups after successful authentication
  • Running R's aov() mixed effects model from Python using rpy2
  • What does the “id” field in an Android “Google Play Music” broadcast intent correspond to?
  • Access to a Matlab gui from the web