MCPcopy Create free account
hub / github.com/gawel/pyquery / closest

Method closest

pyquery/pyquery.py:557–576  ·  view source on GitHub ↗

>>> d = PyQuery( ... ' This is a ' ... ' test ') >>> d('strong').closest('div') [ ] >>> d('strong').closest('.hello') [ ] >>> d('strong').closest('for

(self, selector=None)

Source from the content-addressed store, hash-verified

555 return self._filter_only(selector, elements)
556
557 def closest(self, selector=None):
558 """
559 >>> d = PyQuery(
560 ... '<div class="hello"><p>This is a '
561 ... '<strong class="hello">test</strong></p></div>')
562 >>> d('strong').closest('div')
563 [<div.hello>]
564 >>> d('strong').closest('.hello')
565 [<strong.hello>]
566 >>> d('strong').closest('form')
567 []
568 """
569 result = []
570 for current in self:
571 while (current is not None and
572 not self._copy(current).is_(selector)):
573 current = current.getparent()
574 if current is not None:
575 result.append(current)
576 return self._copy(result, parent=self)
577
578 def contents(self):
579 """

Callers 2

test_closestMethod · 0.80

Calls 3

_copyMethod · 0.95
is_Method · 0.80
appendMethod · 0.80

Tested by 2

test_closestMethod · 0.64