You can use Javascript on anchor tag like:
<script type="text/javascript">
function testClick(id)
{
alert(id);
}
</script>
<a href="#" id="test" onclick="testclick(this.id);">Click</a>
Assuming the tag is well-formed, a tag's attribute can be obtained via Element.getAttribute.
document.getElementById('test').getAttribute('onclick')
// -> "somefunction"
Hopefully you aren't using onclick
for some unscrupulous purpose like storing data.
You should try:
document.getElementById('test').onclick.toString()