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); }); 

learn multiple selector


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -