Select all elements with style="display: none"

Is it possible with Floki to select all elements with style="display: none"?
I have tried

Floki.find(ast, "[style=\"display: none\"]")

but this will not match variants e.g. display:none (no space), or other styles like style="width: 100; display: none"

I am afraid not… although I have never used Floki, looking at the documentation it seems it uses CSS selectors to match elements. Thus, you could match any display: none with or without something in front of it by querying like so:

// html/javascript selector, but it is the same thing
document.querySelectorAll("[style*=\"display: none\"]")

This would match:

  • display: none
  • width: 100%, display: none

It will however not match display:none (without the space). CSS does not allow regular expression style selectors. But maybe you can combine differen Floki calls into one? Pure guess here but:

a = Floki.find(ast, "[style*=\"display: none\"]")
b = Floki.find(ast, "[style*=\"display:none\"]")
total = a ++ b

I will try! Thank you!

I also tried:

Floki.find(tree, ":hidden")

but Pseudo-class "hidden" is not implemented. Ignoring.

1 Like

Yeah, pseudo selectors… I wouldn’t count on it :slight_smile: but I guess my proposal will be good enough. Let me know and if so, mark the question as ‘answered’.