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

Add condtions to element #39

Closed
neverender24 opened this issue Jul 2, 2018 · 2 comments
Closed

Add condtions to element #39

neverender24 opened this issue Jul 2, 2018 · 2 comments

Comments

@neverender24
Copy link

How do I filter which element is being processed?

for example, I have mutiple classes:
$sels = "h2, .pnlDescription, .address";

I want to have a condition with the ".address" since I want to alter the text within it.

if(".address" == "somestring")
{
----code---
}

Where and how can I achieve this one?

@duzun
Copy link
Owner

duzun commented Jul 2, 2018

I would go the other way:

$h2 = $doc->find('h2');
$desc = $doc->find('.pnlDescription');
$address = $doc->find('.address');
// ... do something with these

There are still some other options, but I think they are less performant:

$sels = $doc->find('h2, .pnlDescription, .address');
foreach($sels as $e) switch(true) {
    case $el->hasClass('address'): {
        // ...
    } break;
    case $el->nodeName == 'h2': {
        // ...
    } break;
}

I would like to have ->is($selector) method, but have never had the need for it.

@neverender24
Copy link
Author

Thanks for feedback that's all I need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants