Skip to content

Instantly share code, notes, and snippets.

@garystorey
Created January 15, 2015 21:31
Show Gist options
  • Select an option

  • Save garystorey/816f5b069601f57fa00a to your computer and use it in GitHub Desktop.

Select an option

Save garystorey/816f5b069601f57fa00a to your computer and use it in GitHub Desktop.
/*
<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