简体   繁体   中英

How to remove a child element with simple dom html

I would like to remove th 4 in this html with Child selector of PHP Simple HTML DOM without id/class

<tr>
  <th>some text</th>
  <th>some text</th>
  <th>some text</th>
  <th>some text</th>
  <th>some text</th>
  <th>some text</th>
  <th>some text</th>
  <th>some text</th>
</tr>

Taking $tr as the row you're using, you can select the child with the following:

$fourthTh = $tr->children(4)

You can then remove the child using DOMNode::removeChild() on the parent element:

$tr->removeChild($fourthTh)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM