htmlq icon indicating copy to clipboard operation
htmlq copied to clipboard

Can select element by id/class, but not by children's classes

Open danimesq opened this issue 4 years ago • 2 comments

curl --silent https://www.rust-lang.org/ | htmlq '#get-help.languages' returns empty.

Related to: https://github.com/mgdm/htmlq/issues/34

danimesq avatar Dec 02 '21 17:12 danimesq

Hmm, interesting! I noticed it works if I do curl --silent https://www.rust-lang.org/ | htmlq '#get-help.languages' (with a space in between the two parts of the selector). I'll look further.

mgdm avatar Jan 03 '22 21:01 mgdm

Seems to be a user error. The element with the id get-help does not have the class languages:

<div class="flex flex-column mw8 w-100 measure-wide-l pv2 pv5-m pv2-ns ph4-m ph4-l" id="get-help">

The selector #get-help.languages thus cannot possibly find any valid result. To get the child with the class languages you would need at least a space like #get-help .languages or using any of the common combinators such as > for direct children (see Combinators on MDN)

Same goes for #34, which also does the same mistake (but in a completely unneeded fashion, an id is already good enough of a selector to find one specific element, specifying the selector by adding the id of a parent has no use unless your goal is to spam-open issues to "irritate" developers (see OP's profile description) by using CSS wrong and claiming it to be a bug).

Mitsunee avatar Jan 18 '22 21:01 Mitsunee