Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

html5qp('<p><span>foo</span></p>')->is('span') returns true #51

Open
1 task done
rulatir opened this issue Mar 27, 2024 · 1 comment
Open
1 task done

html5qp('<p><span>foo</span></p>')->is('span') returns true #51

rulatir opened this issue Mar 27, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@rulatir
Copy link

rulatir commented Mar 27, 2024

Guidelines

Description of the bug

As demonstrated by this failing test:

    public function testIsDepth() : void
    {
        $dom = html5qp('<p><span>foo</span></p>');
        self::assertTrue($dom->is('p'), "Should match element held directly in the collection");
        self::assertFalse($dom->is('span'), "Should not match a descendant of element held in the collection");
    }

->is($selector) will return true if any descendant of an element held in the collection matches the selector. This diverges from jQuery specification, as evidenced by this filddle, and IMO that makes ->is() useless. At the very least, the original functionality of jQuery's .is() should be provided somehow.

QueryPath version

3.2.3

PHP Version and environment (server type, cli provider etc., enclosing libraries and their respective versions)

8.3.4 (cli) on up-to-date Arch Linux

Minimal reproducible PHP+HTML snippet to replicate bug

echo html5qp('<p><span>foo</span></p>')->is('span') ? "Is, but shouldn't be\n" : "Isn't, and that's fine\n";
@rulatir rulatir added the bug Something isn't working label Mar 27, 2024
@jakejackson1
Copy link
Member

Thank you for reporting this issue @rulatir. I agree that is() should act like the jQuery equivalent (where possible). It looks like QueryPath's ->is($selector) currently works like ->has($selector), but returns a boolean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants