Permalink
Browse files

hasClass() on an empty set should return false

  • Loading branch information...
1 parent c4ef1de commit 64bc66a50c2147f420d277e6b482a3a04a56a74d @bryfox bryfox committed Aug 24, 2010
Showing with 9 additions and 2 deletions.
  1. +7 −0 spec/tests/core-tests.js
  2. +1 −1 src/IE/core/style.js
  3. +1 −1 src/core/style.js
View
@@ -173,6 +173,13 @@ CoreTests.prototype.run = function () {
test( 'should return false when element does not have the specified class', function(){
equals(x.hasClass('zug'), false, 'Element with id "has-class-element" should not have the class "zug"');
});
+
+ test('should return false when the selector matches zero elements', function () {
+ var y = x$('#this-should-never-exist-in-the-dom');
+ equals(y.length, 0);
+ equals(y.hasClass('bar'), false);
+ });
+
// --
/// dom specs
// --
View
@@ -150,7 +150,7 @@ xui.extend({
hasClass: function(className, callback) {
return (callback === undefined && this.length == 1) ?
hasClass(this[0], className) :
- this.each(function(el) {
+ this.length && this.each(function(el) {
if (hasClass(el, className)) {
callback(el);
}
View
@@ -150,7 +150,7 @@ xui.extend({
hasClass: function(className, callback) {
return (callback === undefined && this.length == 1) ?
hasClass(this[0], className) :
- this.each(function(el) {
+ this.length && this.each(function(el) {
if (hasClass(el, className)) {
callback(el);
}

0 comments on commit 64bc66a

Please sign in to comment.