You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The selector span[foo] works as expected, returning the span element with the id eg.
But no variation of span[data-foo] seems to do the trick. It always selects an empty array.
More generally, any attribute name containing a dash character (-) is not recognized as an attribute selector by node-soupselect. Although I can't find a definitive reference that states attribute names can contain hyphens, they are all over HTML5 and this is contrary to the behavior of CSS on any browser I've tested. (I.e., a selector like:
span[data-foo] { background: green; }
will accurately select the element.)
I haven't tested the change extensively, but I think this is easily addressed by changing line 22 of soupselect.js from:
varattrSelectRe=/^(\w+)?\[([\w-]+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/;// the change is here---------^--^^
since \w matches letters, numbers or underscores ([a-zA-Z0-9_]) but not the dash character (-). Changing the second instance of (\w+) to ([\w-]+) adds dashes into the mix.
It may be sensible to do the same thing to the first instance of \w in that pattern so that tag names can contain hyphens as well.
I can provide pull request for this if desired.
The text was updated successfully, but these errors were encountered:
Given an HTML snippet such as
The selector
span[foo]
works as expected, returning the span element with the ideg
.But no variation of
span[data-foo]
seems to do the trick. It always selects an empty array.More generally, any attribute name containing a dash character (
-
) is not recognized as an attribute selector by node-soupselect. Although I can't find a definitive reference that states attribute names can contain hyphens, they are all over HTML5 and this is contrary to the behavior of CSS on any browser I've tested. (I.e., a selector like:will accurately select the element.)
I haven't tested the change extensively, but I think this is easily addressed by changing line 22 of soupselect.js from:
to
since
\w
matches letters, numbers or underscores ([a-zA-Z0-9_]
) but not the dash character (-
). Changing the second instance of(\w+)
to([\w-]+)
adds dashes into the mix.It may be sensible to do the same thing to the first instance of
\w
in that pattern so that tag names can contain hyphens as well.I can provide pull request for this if desired.
The text was updated successfully, but these errors were encountered: