JQuery hide button before even shown

javascriptjqueryvisualforce

I have installed a managed package that has a static resource (JS). This static resource performs a jQuery "prepend" to show a button. I cannot change the code of this static resource but i have the ability to create another static resource (JS) and write some code for customizations. The thing is: a Visualforce page is loaded (i have no access to the VF Page code) and then my custom static resource is loaded and then the managed package static resource is loaded. Their static resource, performs a prepend on a button, but i want this button to always be hidden. But, although i add the command to hide the button, it is not. I suppose it's because the button is loaded after my command… Has anyone face this problem again? Is there a way to solve it?

Code below:
Managed package static resource code that performs the "prepend"

jQuery(buttons[0]).prepend('<button id="addonman" class="slds-button slds-button--neutral">Add On Manager</button>');
jQuery('#addonman').click(showFullManager)

My static resource

CS.EventHandler.subscribe(CS.EventHandler.Event.AFTER_SHOW_SCREEN_ACTION, function (payload) {
//? Test functionality...
      jQuery("#addonman").hide();
});
  

Best Answer

Assuming it needs to be JavaScript, just add a CSS rule:

CS.EventHandler.subscribe(CS.EventHandler.Event.AFTER_SHOW_SCREEN_ACTION, 
function (payload) {
//? Test functionality...
      document.styleSheets[0].insertRule("#addonman { display: none; }");
});

By adding it as a rule, you can technically do it whenever you want, even before the button is rendered into the page.

If you can choose to import CSS, you can just make it a rule:

#addonman {
  display: none;
}