views:

26

answers:

1

I need a sort of "live" effect on some checkbox - i need that every checkbox since now will be checked by a jquery function attr("checked", true) when they appear.

Is it possible to do?

+1  A: 

You can do this in your $.ajax() success handler, or the success handler of whatever short form of $.ajax() you're using, (e.g. $.post(), $.get(), etc.), like this:

$.ajax({
  //options...
  success: function(data) {
    $("input:checkbox", data).attr("checked", true);
  }
});

This is the most optimal way to accomplish what you're after, by giving it a context to look in...so it's only looking for input:checkbox in the returned result you're now adding to the DOM, not the entire page.

If that's not possible, you can use something like the livequery plugin, like this:

$("input:checkbox").livequery(function() {
  $(this).attr("checked", true);
});

This is more expensive due to the way it looks for new elements to be added, but gets the job done.

Nick Craver