is it possible to manually call a click on a dom object?

Yevgeny Simkin picture Yevgeny Simkin · Jun 9, 2011 · Viewed 7.3k times · Source

I am using addthis and they have a bunch of obfuscated code that I am loathe to dig through in their embedded javascript. I would like to "click" one of their buttons on my page without the user having to touch it.

So, in essence, there is a <a> that contains their button (which their embedded javascript handles when the user clicks it). I would like to "click" it for them, via my own javascript, but don't see anything like a native "clickMe()" function associated with the anchor tag object.

Is it possible to do this, or is it missing from the spec due to security concerns?

Answer

js1568 picture js1568 · Jun 9, 2011

I looked at the AddThis code more carefully and their functionality is have an onclick handler for the parent div of each a. If you know the id of the div you want to click, just put it in this line. As a back up, you can also try click() for the a.

var id = 'atic_facebook'; //for example
document.getElementById(id).onclick();