tags:

views:

72

answers:

1

Hi, I am getting a list of checkboxes from a $.get call in JQuery. Is there anyway I can attach an onclick function to each of these checkboxes from within the parent page.

e.g. The parent page would contain the following code (maybe errors as I have just wrote it off the top of my head and not tested it)

$(document).ready(function(){
  $(":checkbox").click(function(){
    //do some stuff
  }

  $.get('some-url.html', function(data){
    $('checkbox-holder').html(data);
  });
}

Therefore any results returned from 'some-url.html' would automatically have an onclick event

Thanks

+2  A: 

Using $.live() to set this information will cause all dynamically-loaded elements to act in the same manner. Just set this once at the top of your script, and it will do the rest of the work. You don't need to reference it when you do your Ajax requests or anything.

$(":checkbox").live("click", function(){
  // what do you want them to do?
});
Jonathan Sampson
Thanks that worked perfectly
John