Created
June 7, 2018 05:52
-
-
Save fodra/ea61d42ca8289137e762166816b78568 to your computer and use it in GitHub Desktop.
A MutationObserver example.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>title</title> | |
| </head> | |
| <body> | |
| <div id="target"> | |
| <div id="inner"> | |
| stuff | |
| </div> | |
| </div> | |
| <script type="text/javascript"> | |
| (() => { | |
| console.log("starting the script"); | |
| let pagination = this.document.getElementById('target'); | |
| let config = {childList: true, subtree: true}; | |
| let handleSearchResults = (param) => { | |
| console.log("search results done", param, this); | |
| } | |
| let observer = new MutationObserver(handleSearchResults.bind(this)); | |
| observer.observe(pagination, config); | |
| })(); | |
| </script> | |
| </body> | |
| </html> | |
| <!-- | |
| 1. Open this page in a web browser preferably chrome. | |
| 2. Open the console. | |
| 3. Type into the console. | |
| inner = document.getElementById('inner'); | |
| inner.textContent = "modified"; // this should trigger the handleSearchResults function | |
| --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment