-
Notifications
You must be signed in to change notification settings - Fork 20
Query Closest
Thomas Weinert edited this page Jul 12, 2018
·
2 revisions
FluentDOM\Query closest(string $selector [, array|Traversable $context = NULL]);
Get a set of elements containing the closest parent element that matches the specified selector, the starting element included.
$xml = <<<HTML
<html>
<head>
<title>Examples: FluentDOM\Query::closest()</title>
</head>
<body>
<ul class="myList">
<li class="red"><b>The <i>first <u>item</u></i></b>.</li>
<li class="green"><b>The <i>second <u>item</u></i></b>.</li>
<li class="yellow"><b>The <i>third <u>item</u></i></b>.</li>
<li class="blue"><b>The <i>fourth <u>item</u></i></b>.</li>
</ul>
<p>
Class of the last clicked item: <span id="display"> </span>
</p>
</body>
</html>
HTML;
$fdQuery = FluentDOM($xml, 'text/html');
echo $fdQuery
->find('//u')
->closest('self::li')
->addClass('foundIt');
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><head><title>Examples: FluentDOM\Query::closest()</title></head><body>
<ul class="myList"><li class="red foundIt"><b>The <i>first <u>item</u></i></b>.</li>
<li class="green foundIt"><b>The <i>second <u>item</u></i></b>.</li>
<li class="yellow foundIt"><b>The <i>third <u>item</u></i></b>.</li>
<li class="blue foundIt"><b>The <i>fourth <u>item</u></i></b>.</li>
</ul><p>
Class of the last clicked item: <span id="display"> </span>
</p>
</body></html>
- Home
- Getting Started
- Tasks
- Plugins
- Functions
- Lists
- Creator (5.1)
- CSS Selectors
- Convertors
- Loaders
- Serializers (5.1)
- Transformers (5.1)
- Extended DOM
- XMLReader (6.1)
- XMLWriter (6.1)
- Interfaces