2

Is there any jQuery NextUntil function for phpQuery? In case I have this HTML structure:

<table id="m" width="100%">
    <tbody>
        <tr class="x" align="center"></tr>
        <tr></tr>
        <tr class="n"></tr>
        <tr></tr>
        <tr class="n"></tr>
        <tr></tr>
        <tr class="x" align="center"></tr>
        <tr class="n"></tr>
        <tr></tr>
        <tr class="n"></tr>
        <tr></tr>
        <tr class="n"></tr>
        <tr></tr>
    </tbody>
</table>

All I want to do is getting the elements between "tr.x" using phpQuery. In jQuery we can do that with NextUntil() function.

1 Answer 1

1

I think this will work for your purposes:

$i = 0;
foreach($children as $child){
    if($i == 2){ break; }
    $i = (pq($child)->attr('class') == 'x') ? ($i + 1) : $i;
    if($i == 0){ continue; }

    echo pq($child)->text();
}

note: this will also exclude all tr elements before the first tr.x

for example if the html was..

<tbody>
    <tr class="n">h</tr>
    <tr class="x" align="center">a</tr>
    <tr>b</tr>
    <tr class="n">c</tr>
    <tr>d</tr>
    <tr class="n">e</tr>
    <tr>f</tr>
    <tr class="x" align="center">g</tr>
    <tr class="n">h</tr>
    <tr></tr>
    <tr class="n"></tr>
    <tr></tr>
    <tr class="n"></tr>
    <tr></tr>
</tbody>

the output would be

a
b
c
d
e
f
g

hope that helps

Sign up to request clarification or add additional context in comments.

Comments

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.