Skip to content

Commit

Permalink
Added a note in DocumentFragment.querySelector to explain why blacksl…
Browse files Browse the repository at this point in the history
…ashes need to be double escaped
  • Loading branch information
simonvarey committed Oct 16, 2024
1 parent 2023c16 commit 9018af0
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion files/en-us/web/api/documentfragment/queryselector/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const el = documentfragment.querySelector(".myclass");
The string argument pass to `querySelector` must follow the CSS syntax. To
match ID or selectors that do not follow the CSS syntax (by using semicolon or space
inappropriately for example), it's mandatory to escape the wrong character with a
double back slash:
double backslash:

```html
<div id="foo\bar"></div>
Expand All @@ -66,6 +66,9 @@ double back slash:
</script>
```

> [!NOTE]
> A double backslash is necessary here because backslashes themselves need to be escaped by a backslash in JavaScript string literals. This also means that a backslash in an ID or selector must be represented by four backslashes. See [String literals](/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#string_literals) for more details.
## Specifications

{{Specifications}}
Expand Down

0 comments on commit 9018af0

Please sign in to comment.