JSFiddle - React, Tailwind, and code Playground

HTML

<div data-global-id="168" class="remove-as-favorite">remove as favorite</div>

JavaScript

var global_id = "";
var $foo;

$('.remove-as-favorite').on('click',function(){
    
    $foo = $(this);
    //var global_id=$(this).data('global-id'); // THIS IS WRONG
    // If you want to use global var do this as below.
   global_id=$(this).data('global-id');    
    
  // this works
  alert('here i am in something: ' + global_id);
  // this doesn't work
  event_handler.remove_as_favorite(); 
});

event_handler={

  remove_as_favorite: function(){
   // var global_id=$(this).data('global-id');
      global_id=$foo.data('global-id');
    alert("here i am global_id:" + global_id);

  }
}