December 2023
Intermediate to advanced
242 pages
5h 28m
English
| Recipe 72 | Highlighting Text in Real Time |
Suppose you want to add a search functionality to your application that behaves similarly to Google Chrome’s “find in page” tool. With this feature, as the user types their search query into the search field, Chrome highlights the corresponding text on the page in real time. This enables users to quickly locate the information they are searching for without having to manually scan the entire page.
Define an HTML page with an input element and a div element containing some text. The input element should have an ID of “search-input,” and the div element should have an ID of “search-results”:
| | <!DOCTYPE html> |
| | <html> |
| | <head> |
| |
Read now
Unlock full access