diff --git a/B.js b/B.js index e0d8c71..d9245f2 100644 --- a/B.js +++ b/B.js @@ -29,7 +29,7 @@ function B(els, attrs) { // Map a function to the first element in 'this' B.prototype.mapOne = function(callback) { var m = this.map(callback); - return m.length > 1 ? m : m[0]; + return m.length > 1 ? m[0] : m; }; // Update css for each element in 'this' @@ -57,6 +57,13 @@ function B(els, attrs) { } }; + // Check if the first element has the requested class + B.prototype.hasClass = function(cls) { + return this.mapOne(function(el){ + return (' ' + el.className + ' ').indexOf(' ' + cls + ' ') > -1; + }); + } + // Add a class to each element in 'this' B.prototype.addClass = function(classes) { var className = "";