2

I am binding a click event in jquery by:

$('#myButton').bind('click',  onButtonClicked);

It works great the first time, but then the view gets rerendered and although I am rebinding the event, it doesn't seem to be working.

I am debugging via firebug and how do I know using JQuery that the click event has been assigned to this button? It doesn't appear to get translated to a onClick event in the HTML.

EDIT:

I think the issue appears to be because I am doing something like this:

$("#myDiv").html("<input type='button' id='myButton'/>");
$('#myButton').bind('click',  onButtonClicked);

Is this valid? The $("#myButton").data("events") appears to have a click event assigned to it, but it does nothing when I click the button.

Dusty
  • 2,159
  • 3
  • 23
  • 26

3 Answers3

1

Here is a start jQuery find events handlers registered with an object

$('#myButton').data('events');

You can then iterate over the returned object to see what events are bound.

$.each($("#myButton").data("events"), function(i, e) {
    alert(i);
});
Community
  • 1
  • 1
John Kalberer
  • 5,690
  • 1
  • 23
  • 27
0

Don't know wether I understand you but here is my try:

You should add it to the document ready:

$(document).ready(function() {
  $('#myButton').bind('click',  onButtonClicked);
});

If you are adding element later dynamically you can use jQuery's live() or even better delegate()

http://api.jquery.com/live/

http://api.jquery.com/delegate/

delegate would be the better option performance wise

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
0

You have to go to html tab, select your node and then click on the green link (the one with "object{events.......}") and then you can see all events attached to the node

enter image description here

Otherwise you can use visual event that creates an overlay that shows all events on your page. It's very useful.

Nicola Peluchetti
  • 76,206
  • 31
  • 145
  • 192