Permalink
Browse files

Fix #2 -- hasClass should only apply to current elements, not children.

  • Loading branch information...
1 parent 040f645 commit 2747f710f71d0002221dd61866414fc8379fbe05 Paul Craciunoiu committed Sep 30, 2011
Showing with 11 additions and 1 deletion.
  1. +5 −1 pyquery/pyquery.py
  2. +6 −0 pyquery/test.py
View
@@ -650,7 +650,11 @@ def hasClass(self, name):
..
"""
- return self.is_('.%s' % name)
+ for tag in self:
+ classes = set((tag.get('class') or '').split())
+ if name in classes:
+ return True
+ return False
def addClass(self, value):
"""Add a css class to elements::
View
@@ -303,6 +303,12 @@ def opener(url):
doc = pq(url='http://example.com', opener=opener)
assert len(doc('.node')) == 1, doc
+class TestHasClass(unittest.TestCase):
+ def test_child_has_class(self):
+ doc = pq("""<div id="test" class="on"><div class="off"></div></div>""")
+ assert doc('#test').hasClass('on')
+ assert not doc('#test').hasClass('off')
+
class TestCallback(unittest.TestCase):
html = """
<ol>

0 comments on commit 2747f71

Please sign in to comment.