Last active
August 29, 2015 14:14
-
-
Save djalmajr/1a6645375e76e14044b5 to your computer and use it in GitHub Desktop.
Toggle element edit
This file contains 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
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