I have a website that load some JS code from url which have select2() function, but i don't know why I can't call or use it using injected script (chrome extension) and got Uncaught TypeError: $(...).select2 is not a function. But I can run JQuery syntax by the injected script, the difference is JQuery.min.js script loaded inside the <head> tag but that select2 script is inside the <body> tag. Is there any way to access selec2() function without changing the website (like rearrange the script or others)? thank you!
This are the script of my custom chrome extension
const batchscp = function(){
const injectElement = document.createElement('div');
injectElement.className = "custombtn btn";
injectElement.id = "mybtn";
$('body').append(injectElement);
spn = //many html elements to inject which contain a button with id=auto
$('#mybtn').append(spn);
}
batchscp();
$('#auto').click(function (e) {
e.preventDefault();
$('.select2').select2(); //Uncaught TypeError: $(...).select2 is not a function
$('#logisticsAdd').val('65').trigger('change');
});