skip to Main Content

Is there any way to get the Bootstrap version via calling a function? I did some research but couldn’t find any way. The version information is included in the comments at the beginning like this:

`/*!

But in case the comments are removed how do I get the bootstrap version? Bootstrap plugins have a version defined in them but I’m looking for the general Bootstrap version, not version of a particular plugin.

6

Answers


  1. The version of each of Bootstrap’s jQuery plugins can be accessed via the VERSION property of the plugin’s constructor. For example, for the tooltip plugin:

    $.fn.tooltip.Constructor.VERSION // => "3.3.7"
    

    src //getbootstrap.com/javascript/#js-version-nums

    if you mean from the css, then yu ahve to AJAX the file and .match(/v[.d]+[.d]/);

    Login or Signup to reply.
  2. You can use this code found here :

      var getBootstrapVersion = function () {
      var deferred = $.Deferred();
    
      var script = $('script[src*="bootstrap"]');
      if (script.length == 0) {
        return deferred.reject();
      }
    
      var src = script.attr('src');
      $.get(src).done(function(response) {
        var matches = response.match(/(?!v)([.d]+[.d])/);
        if (matches && matches.length > 0) {
          version = matches[0];
          deferred.resolve(version);
        }
      });
    
      return deferred;
    };
    
    getBootstrapVersion().done(function(version) {
      console.log(version); // '3.3.4'
    });
    
    Login or Signup to reply.
  3. This spinoff of the Constructor method adds a fallback plugin and returns an array:

    var version = ($().modal||$().tab).Constructor.VERSION.split('.');
    

    You can access the major revision with version[0], of course.

    Login or Signup to reply.
  4. you can find bootstrap version here: https://getbootstrap.com/docs/4.3/getting-started/javascript/#version-numbers

    $.fn.tooltip.Constructor.VERSION // => "4.3.1"
    
    Login or Signup to reply.
  5. Checked on the jQuery-less Bootstrap5, to get the version you just neeed

    let version = bootstrap.Tooltip.VERSION
    
    Login or Signup to reply.
  6. If you want a solution that works for all the currently supported versions of Bootstrap (3.x, 4.x, 5.x), this should work:

    var version = typeof bootstrap === 'undefined' ?
       $().tooltip.Constructor.VERSION : bootstrap.Tooltip.VERSION;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search