Selectors Level 3: 4. Selector syntax
Characters in Selectors can be escaped with a backslash according to the same escaping rules as CSS. [CSS21].
CSS21: 4.1.3 Characters and case
In CSS, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646 characters U+00A0 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a digit, two hyphens, or a hyphen followed by a digit. Identifiers can also contain escaped characters
The .
(Full Stop) is U+002E
so not an allowed character as part of the identifier and has to be escaped due to that.
The .
in #music_playlist-2.7
would indicate a selector of this kind #idIdentifer.classIdentifer
but .7
is not a valid class identifier as identifiers cannot start with a digit, so depending on how the parser for the selector is implemented it might just ignore that error in the selector, and count .7
as part of the previous identifier, but that's not correct, at least I can't find any part about that in the specs that would justify this:
Selectors Level 3:4. Selector syntax
A selector is a chain of one or more sequences of simple selectors separated by combinators. One pseudo-element may be appended to the last sequence of simple selectors in a selector.
A sequence of simple selectors is a chain of simple selectors that are not separated by a combinator. It always begins with a type selector or a universal selector. No other type selector or universal selector is allowed in the sequence.
A simple selector is either a type selector, universal selector, attribute selector, class selector, ID selector, or pseudo-class.
The universal selector, written as a CSS qualified name [CSS3NAMESPACE] with an asterisk (* U+002A) as the local name, [...] If a universal selector represented by *
[...] is not the only component of a sequence of simple selectors selectors or is immediately followed by a pseudo-element, then the *
may be omitted and the universal selector's presence implied.
So if you want to use the ID music_playlist-2.7
in your querySelectorAll
would write it that way:
document.querySelectorAll('#music_playlist-2\\.7 input[name="payment_form_function"]');
Or if you want to use it in a css rule:
#music_playlist-2\.7 input[name="payment_form_function"] {
color: red;
}