I am writing code for an online store, I can only upload one custom js file and I am facing a problem. I need to load a library to work with input masks and then apply the mask to one of the fields on the page.
The problem is that the function of creating the mask apparently works before the library is loaded and I get the error "Uncaught TypeError: $ (...). UsPhoneFormat is not a function".
How can I solve this problem?
My code:
var phone = document.createElement("script");
phone.type = "text/javascript";
phone.src = "https://unpkg.com/jquery-input-mask-phone-number@1.0.14/dist/jquery-input-mask-phone-number.js";
document.head.appendChild(phone);
$('#ec-phone').usPhoneFormat({
format: '+7 (xxx) xxx-xx-xx',
});