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.