Last active
August 9, 2016 19:55
-
-
Save TravelingTechGuy/69e86d6f3e26d60a53536abe4046d35d to your computer and use it in GitHub Desktop.
Disable paste event
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
//1. Plain JavaScript | |
document.getElementById("txtPassword").addEventListener("paste", function(e) { | |
e.preventDefault(); | |
}); | |
//2. If jQuery is used on the page, it might look like this: | |
$('#txtPassword').bind("paste", function(e) { | |
e.preventDefault(); | |
}); | |
//3. Sometimes, event and function are separate: | |
document.getElementById("txtPassword").addEventListener("paste", preventPaste); | |
//...later in the file... | |
function preventPaste(e) { | |
e.preventDefault(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment