Matches elements which contain at least one element that matches the specified selector. https://api.jquery.com/has-selector/ >>> from pyquery import PyQuery >>> d = PyQuery(' ') >>> d('.foo:has(".baz")')
(self, xpath, function)
| 442 | return xpath |
| 443 | |
| 444 | def xpath_has_function(self, xpath, function): |
| 445 | """Matches elements which contain at least one element that matches |
| 446 | the specified selector. https://api.jquery.com/has-selector/ |
| 447 | |
| 448 | >>> from pyquery import PyQuery |
| 449 | >>> d = PyQuery('<div class="foo"><div class="bar"></div></div>') |
| 450 | >>> d('.foo:has(".baz")') |
| 451 | [] |
| 452 | >>> d('.foo:has(".foo")') |
| 453 | [] |
| 454 | >>> d('.foo:has(".bar")') |
| 455 | [<div.foo>] |
| 456 | >>> d('.foo:has(div)') |
| 457 | [<div.foo>] |
| 458 | |
| 459 | .. |
| 460 | """ |
| 461 | if function.argument_types() not in (['STRING'], ['IDENT']): |
| 462 | raise ExpressionError( |
| 463 | "Expected a single string or ident for :has(), got %r" % ( |
| 464 | function.arguments,)) |
| 465 | value = self.css_to_xpath( |
| 466 | function.arguments[0].value, prefix='descendant::', |
| 467 | ) |
| 468 | xpath.add_post_condition(value) |
| 469 | return xpath |
nothing calls this directly
no test coverage detected