How can I get the bootstrap version via javascript?

Is there a way to get the version bootstrap

through a function call? I've done some research but couldn't find any way, version information is included in the comments at the beginning like this:

/*! * Bootstrap v3.3.7 (http://getbootstrap.com) * Copyright 2011-2016 Twitter, Inc. * Licensed under the MIT license */

But in case of deleting comments, how can I get the bootstrap version? Bootstrap modules have a version defined in them, but I'm looking for a generic bootstrap version, not a specific plugin version.

+14


source to share


4 answers


A version of each of the jQuery Bootstrap plugins can be accessed through the VERSION property of the plugin constructor. For example, for a tooltip plugin:

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



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

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

+27


source


This code can be 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'
});

      

+10


source


This additional Constructor method adds a fallback plugin and returns an array:

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

      

You can of course access the main revision from version[0]

.

+2


source


You can find the bootstrap version here: https://getbootstrap.com/docs/4.3/getting-started/javascript/#version-numbers

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

      

0


source







All Articles