Fake "click" to activate an onclick method

yoavf picture yoavf · Dec 7, 2008 · Viewed 144.6k times · Source

I have an element with an onclick method.

I would like to activate that method (or: fake a click on this element) within another function.

Is this possible?

Answer

Ben picture Ben · Dec 7, 2008

Once you have selected an element you can call click()

document.getElementById('link').click();

see: https://developer.mozilla.org/En/DOM/Element.click

I don't remember if this works on IE, but it should. I don't have a windows machine nearby.