Created
January 15, 2015 21:31
-
-
Save garystorey/816f5b069601f57fa00a to your computer and use it in GitHub Desktop.
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
| /* | |
| <p>But haven't the sweetest idea <button>DELETE</button></p> | |
| <p>To me buzz is <button>INSERT</button></p> | |
| We'll use the two methods to do two simple things with this HTML: (1) Remove the word "idea" and (2) insert the word "onomatopoeia". Here's the JavaScript: | |
| */ | |
| var pars = document.querySelectorAll('p'), | |
| btns = document.querySelectorAll('button'), | |
| text; | |
| btns[0].addEventListener('click', function () { | |
| text = pars[0].firstChild; | |
| text.deleteData(25, 4); | |
| }, false); | |
| btns[1].addEventListener('click', function () { | |
| text = pars[1].firstChild; | |
| text.insertData(14, 'onomatopoeia '); | |
| }, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment