Home > Back-end >  Check for bootstrap-5 without jQuery
Check for bootstrap-5 without jQuery

Time:11-05

I need to check if bootstrap-5 JavaScript file is loaded. There is a simple way of doing it using jQuery. For example, a common asp-fallback test expression for using Bootstrap JavaScript file from CDN is as follows:

asp-fallback-test="window.jQuery && window.jQuery.fn && window.jQuery.fn.modal"

Since older versions of Bootstrap JavaScript files relied on jQuery for their own operation, the above test worked well. However, Bootstrap 5 is designed to be used without jQuery, so a test that relies on window.jQuery is no longer appropriate.

What is a minimal expression that returns a truthy value only when one of the Bootstrap-5 JavaScript files is loaded?

CodePudding user response:

You can check window.bootstrap to verify Bootstrap 5 is loaded.

  • Related