Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get bootstrap version via javascript?

Tags:

Is there any way to get 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:

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

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.

like image 258
Selman Genç Avatar asked Apr 05 '17 14:04

Selman Genç


People also ask

Can I use Bootstrap with JavaScript?

Nearly all Bootstrap plugins can be enabled and configured through HTML alone with data attributes (our preferred way of using JavaScript functionality). Be sure to only use one set of data attributes on a single element (e.g., you cannot trigger a tooltip and modal from the same button.)

How do I know if Bootstrap is added?

We can check Bootstrap-specific method is available or not. Syntax: var bootstrap = (typeof $(). "Bootstrap-specific method" == 'function');


2 Answers

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]/);

like image 188
roberto tomás Avatar answered Oct 20 '22 16:10

roberto tomás


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' }); 
like image 26
Nico_ Avatar answered Oct 20 '22 16:10

Nico_