JQuery - Add click event to multiple elements -
i have following:
$('#applicationsgrid tbody').on('click', 'td.details-control', function () { var formatteddata = dosomething(); $(this).parent('tr').after(formatteddata); }); $('#applicationsgrid tbody').on('click', 'td.child-details-control', function () { var formatteddata = dosomething(); $(this).parent('tr').after(formatteddata); }); $('#applicationsgrid tbody').on('click', 'td.grand-child-details-control', function () { var formatteddata = dosomething(); $(this).parent('tr').after(formatteddata); });
how can combine "on" events 1 click event take care of clicking on 'td.details-control', 'td.child-details-control', 'td.grand-child-details-control', can reduce duplicate code?
use multiple selector (“selector1, selector2, selectorn”) in jquery
$('#applicationsgrid tbody').on('click', 'td.details-control,td.child-details-control,td.grand-child-details-control', function () { var formatteddata = dosomething(); $(this).parent('tr').after(formatteddata); });
Comments
Post a Comment