3

HTML:

<ul>
 <li><a></a>
  <ul>
   <li></li>
   <li></li>
  </ul>
 </li>
 <li>
  ...
 </li>
</ul>

For parent ul:first-of-type, what would be the selector for it's (direct) child li elements, in order to parse the descendant li elements separately?

4
  • 1
    @Gordon: I don't really understand why this question was put as off-topic. It's clear what I want to achieve, even got an answer. Commented Jul 24, 2013 at 9:12
  • It was closed because it didn't demonstrate a minimal understanding of the problem being solved. In particular, you do not explain what you have tried to solve this problem or why the documentation at simplehtmldom.sourceforge.net/manual.htm didn't help. We expect you to do thorough research before asking. See stackoverflow.com/questions/ask-advice and meta.stackexchange.com/questions/156810/… Commented Jul 24, 2013 at 9:27
  • I did read the documentation, but thought there is some other way to do so: something like "li not li li". The information I found was as below, but it wasn't complete solution, as there were other elements in ul than li, but... as it is not valid html, I accepted the answer below. Commented Jul 24, 2013 at 18:16
  • Well, the point is: you didn't include that information in your question, when our question checklist and Ask Advice asks you to. Always include what you have tried and researched, so people can see you are not a lazy help vampire. I am releasing the question from on-hold now, but please keep it in mind for your future questions. Thanks. Commented Jul 24, 2013 at 19:32

1 Answer 1

4

In Jquery you can simply use this selector : ul > li

Update:-

Using Simple DOM:-

<ul class="listitems">
 <li><a></a>
  <ul>
   <li></li>
   <li></li>
  </ul>
 </li>
 <li>
  ...
 </li>
</ul>

Simple HTML Dom code to get just the first level li items:

$html = file_get_html( $url );
$first_level_items = $html->find( '.listitems', 0)->children();

foreach ( $first_level_items as $item ) {
    ... do stuff ...
}
Sign up to request clarification or add additional context in comments.

1 Comment

Note that SimpleHtmlDom doesnt support >. See simplehtmldom.sourceforge.net/manual.htm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.