Skip to content

Commit 4dc98c2

Browse files
dletoreygithub-actions[bot]Josh-Cenabsmth
authored
corrected spelling and updated example to show result on page (mdn#39750)
* corrected spelling and updated example to show result on page * Update files/en-us/web/api/highlight/index.md Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * updated heading structure * updated html in examplle to reset the ranges * added nolint to stop linter altering the positions of the ranges * Update files/en-us/web/api/highlight/index.md Co-authored-by: Joshua Chen <sidachen2003@gmail.com> * added the s back to examples * Update files/en-us/web/api/highlight/index.md --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Joshua Chen <sidachen2003@gmail.com> Co-authored-by: Brian Smith <brian@smith.berlin>
1 parent 49f27d5 commit 4dc98c2

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

files/en-us/web/api/highlight/highlight/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ new Highlight(range1, range2, /* …, */ rangeN)
2222
### Parameters
2323

2424
- `range1`, …, `rangeN` {{optional_inline}}
25-
- : One ore more initial {{domxref("Range")}} objects to add in the new highlight.
25+
- : One or more initial {{domxref("Range")}} objects to add in the new highlight.
2626

2727
### Return value
2828

files/en-us/web/api/highlight/index.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,28 @@ _The `Highlight` interface doesn't inherit any methods_.
5454

5555
## Examples
5656

57-
The following example demonstrates how to create ranges, instantiate a new `Highlight` object for them, and register it to be styled on the page:
57+
The following example demonstrates how specific parts of a block of text can be highlighted.
58+
59+
```html-nolint
60+
<p class="foo">Lorem ipsum dolor sit amet consectetur adipisicing elit. Exercitationem
61+
sapiente non eum facere? Nam rem hic culpa, ipsa rerum ab itaque consectetur
62+
molestiae dolores vitae! Quo ex explicabo tempore? Tenetur.</p>
63+
```
64+
65+
This JavaScript code creates [ranges](/en-US/docs/Web/API/Range), instantiates a new `Highlight` object for them, and [registers it](/en-US/docs/Web/API/HighlightRegistry/set) to be styled on the page:
5866

5967
```js
60-
const parentNode = document.getElementById("foo");
68+
const parentNode = document.querySelector(".foo");
69+
const textNode = parentNode.firstChild;
6170

6271
// Create a couple of ranges.
6372
const range1 = new Range();
64-
range1.setStart(parentNode, 10);
65-
range1.setEnd(parentNode, 20);
73+
range1.setStart(textNode, 6);
74+
range1.setEnd(textNode, 21);
6675

6776
const range2 = new Range();
68-
range2.setStart(parentNode, 40);
69-
range2.setEnd(parentNode, 60);
77+
range2.setStart(textNode, 57);
78+
range2.setEnd(textNode, 71);
7079

7180
// Create a custom highlight for these ranges.
7281
const highlight = new Highlight(range1, range2);
@@ -83,6 +92,10 @@ The following CSS code snippet demonstrates how to style the registered custom h
8392
}
8493
```
8594

95+
### Result
96+
97+
{{EmbedLiveSample("example", "100%", '100')}}
98+
8699
## Specifications
87100

88101
{{Specifications}}

0 commit comments

Comments
 (0)