How to detect which Bootstrap version is used from JavaScript? How to detect which Bootstrap version is used from JavaScript? javascript javascript

How to detect which Bootstrap version is used from JavaScript?


The version of each of Bootstrap's jQuery plugins can be accessed via the VERSION property of the plugin's constructor

$.fn.tooltip.Constructor.VERSION


As suggested in comments, the only function that seems to be removed in Bootstrap 3 was typehead, even then - there doesn't seem to be a reliable way of detecting which Bootstrap version the site has loaded.

var bsVersion = ( typeof $.fn.typeahead !== 'undefined' ? '2.3.2' : '3.0.0' );


In case you want to grab the Bootstrap's version based on its comments in CSS file, you could use the following code. It's been tested, to make sure it works.

Assume, that Bootstrap's CSS file contains a comment displaying a version (it always does actually):

/*! * Bootstrap v3.0.3 (http://getbootstrap.com) * Copyright 2013 Twitter, Inc. * Licensed under http://www.apache.org/licenses/LICENSE-2.0 */

Remember about same origin policy, when using jQuery.get() method, where the request will not be successfully executed, if data-source is from a different domain, subdomain, or protocol.

$(function () {    $.get("dist/css/bootstrap.min.css", function (data) {        var version = data.match(/v[.\d]+[.\d]/);        alert(version);    });});

Example Online

The online example above, is based on grabbing local file from jsfiddle.net but not from getbootstrap.com, because of the security reasons that were already mentioned, and extracting a comment, which should display accordingly after you hit Run button.

You could also test it just by going to getbootstrap.com, opening a console and pasting the code. After you run it, you will get the current version of Bootstrap displayed, which is v3.0.3 at the moment.