views:

604

answers:

2

I found the way to check if event exists on element. But it's not work on the events which is not delegated by jQuery...

When I try,

$("a").data("events");

for this.

<a href="#" onClick="alert('Hello, World!')" />

It returned undefined.

Is there any way to check if onClick exists on elements with jQuery?

Thanks.

+1  A: 

You can do:

if ($('a').attr("onClick") != undefined) {}
Tim
Oops! Over looked... :)
Ei Maung
A: 

I think the following things should also work

if ($(yourElement).attr("onClick").length != 0) {}

if ($(yourElement).attr("onClick").size() != 0) {}

Thanks

Mahesh Velaga