In a scenario like below how to get imgt in console:
function test(e){
let tg = e.target.attr('data-tg');
console.log(tg); // error - target is undefined
}
$('button').on('click', function(e){
let fn = $(this).attr('data-fn');
window[fn]();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button data-tg='imgt' data-fn='test'>CLICK</button>
e.targetis only an element and will not be able to have.attr()function. This should show in your Console. Suggest wrapping it,$(e.target).attr()to get proper result.window[fn]()would be called with argument, shouldn't it? (window[fn](e))