Skip to content

Instantly share code, notes, and snippets.

@djalmajr
Last active August 29, 2015 14:14
Show Gist options
  • Save djalmajr/1a6645375e76e14044b5 to your computer and use it in GitHub Desktop.
Save djalmajr/1a6645375e76e14044b5 to your computer and use it in GitHub Desktop.
Toggle element edit
var el = document.querySelector('.el'),
btn = document.querySelector('.btn-edit');
el.addEventListener('input', function (e) {
console.log(e.currentTarget.textContent);
});
btn.addEventListener('click', function () {
var isEditing = el.getAttribute('contenteditable');
if (isEditing) {
el.removeAttribute('contenteditable');
} else {
el.setAttribute('contenteditable', true);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment