Variable as selector

Variable as selector

Hi,
       i am trying to use variable in selector but its not working. i declare a variable when i click on table name (RCDT) and then i use variable as table id. it seems variable value is not being used in table selector. i can get variable value outside of function. following is my code.. here is full code.  https://fiddle.jshell.net/1mfgny9j/14/

Thanks,

$('div #selectgroupname').on('click', function() {

            if($(this).hasClass('clicked')) {
          $(this).removeClass("clicked");
        } else {
          $(this).addClass('clicked');
}
window.selectedgrouptableid = 'rcdtgrouptable';
    });

    $('div #'+window.selectedgrouptableid+' tr').on( 'click', function() {
     $(this).remove();    
console.log($(this).html());
});