Add 'hasClass' function
Also fix issue with the mapOne function
This commit is contained in:
parent
e1123273c4
commit
04e000fa8d
9
B.js
9
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 = "";
|
||||
|
Loading…
Reference in New Issue
Block a user