Mala Mala - 9 months ago 51
Javascript Question

Javascript: get element's current "onclick" contents

I have a page with the following code:

<a id="test" href="someurl" onclick="somefunction">link</a>

I need to actually read the 'onclick' data. As such, I would like something to the effect of


Sadly, it returns
. What do I need to do to get

Answer Source

Assuming the tag is well-formed, a tag's attribute can be obtained via Element.getAttribute.

// -> "somefunction"

Hopefully you aren't using onclick for some unscrupulous purpose like storing data.