Detecting closest or parent div
I have the following script:
http://jsfiddle.net/开发者_如何学运维oshirowanen/pALBV/
How do I make this more dynamic, so I do not have to manually specify the button clicks for each button if the number of buttons on screens is unknown as in the end result, the containers along with the container content will be database generated.
At the moment, I have only specified button_2 in jquery script.
try this:
$(function() {
$(':button').click(function() {
$(this).closest('.container').fadeOut('slow', function() {
$(this).remove();
});
});
});
This works:
$(function() {
$('input[type="button"]').click(function() {
var container = $(this).parent().parent();
container.fadeOut('slow', function() {
container.remove();
});
});
});
精彩评论