I have a requirement where I have to fire click event on table header on click of other table header (2 different tables), but trigger is not fired on the table when in a loop. Although if I hardcode and bind the trigger to individual element, it works.
Currently, the JS looks like something like this:
var outsideHeaders = $("#header th");
var tableHeaders = $(".dataTable th");
for(var cnt = 0; cnt< outsideHeaders.length; cnt++)
{
$(outsideHeaders[cnt]).bind('click',function(){
$(tableHeaders[cnt]).trigger('click');
});
}
Please provide solution for this!
Updated:
This is how my code looks now:
var outsideHeaders = $("#header th");
var tableHeaders = $(".dataTable th");
for(var cnt = 0; cnt< outsideHeaders.length; cnt++)
{
(function(headerCnt){
$(outsideHeaders[headerCnt]).bind('click',function(){
$(tableHeaders[headerCnt]).trigger('click');
});
})(cnt);
}