(This problem is specific to Bootstrap Studio)
I need to include a piece of JS that is specific to just one page.
jQuery.js) by BSS, thus I see $ is not defined error when my script runs.What is my way out?
You have :
1) to wait jQuery is loaded, you can do this with such code :
$( document ).ready(function() {
// Handler for .ready() called.
if (window.location.pathname == '/mypage.php') {
// execute my custom code
}
});
or
var waitForJQuery = setInterval(function () {
if (typeof $ != 'undefined') {
// place your code here.
if (window.location.pathname == '/mypage.php') {
// execute my custom code
}
clearInterval(waitForJQuery);
}
}, 50);
2) if you want to execute your code only on a custom page, you can check on which page you are, and if you are on the good page, you execute your custom code
if (window.location.pathname == '/mypage.php') {
// execute my custom code
}
See more possibilities here : Best way to execute js only on specific page
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With