Simple HTML DOM - (direct) child selector
-
28-10-2019 - |
Question
How can i get the inner text of the a
element with text Title?
I'm trying with $html->find('#someid p > a')
but it includes all nested descendant a
elements.
<div id="someid">
<tr>... Same structure ...<tr>
<tr>
<td>
<p>
<a href="#">Title</a>
<br>
<span class="someClass">
<a href="#">text1</a>
<a href="#">text2</a>
<a href="#">text3</a>
<a href="#">text4</a>
</span>
</p>
<p>text5</p>
</td>
<td>text6</td>
</tr>
<tr>...<tr>
</div>
Solution
Try:
$e = $html->find(''#someid p > a', 0); //or type first_child
OTHER TIPS
Have you tried using filter(':first')
or filter(':first-child')
? You may also try using the ->firstChild
lookup.
I assume you need the first descendent. Otherwise, you could consider using an id for the specific anchor tag.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow