jQuery click not applied to repainted/injected items
I have a simple piece of jQuery which injects a new row (...) which contains a select, a text box and some radio buttons to an existing table using the following:
$(':radio').click(function() {
$('#bdTable tr:last').after(makeHTML());
});
now this is all well and good however the click event only applies to the original row that was rendered on the page and not the new rows that we generate using the above code. I want al开发者_JAVA技巧l radio buttons to fire this functionality when clicked.
Does anyone know how I apply the click event to the new rows too?
I can expand if necessary.
You could use delegate():
$('#bdTable').delegate(':radio', 'click', function(){
$('#bdTable tr:last').after(makeHTML());
});
Use live as below
$(':radio').live("click", function() {
$('#bdTable tr:last').after(makeHTML());
});
Check out jQuery's
live() function.
$(':radio').live('click', function() {
$('#bdTable tr:last').after(makeHTML());
});
Use:
$(':radio').live(function() {
$('#bdTable tr:last').after(makeHTML());
});
精彩评论