Created
January 6, 2025 08:43
-
-
Save vielhuber/891117e05a1adfc1cd886d78b10d2f8c to your computer and use it in GitHub Desktop.
input textarea auto capitalize uppercase
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
<!DOCTYPE html> | |
<html lang="de"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>autocaps</title> | |
<script> | |
document.addEventListener('DOMContentLoaded', () => { | |
if( document.querySelectorAll('.autocaps').length > 0 ) { | |
document.querySelectorAll('.autocaps').forEach($el => { | |
$el.addEventListener('input', (e) => { | |
let p = $el.selectionStart; | |
$el.value = $el.value.toUpperCase(); | |
$el.setSelectionRange(p, p); | |
}); | |
}); | |
} | |
}); | |
</script> | |
</head> | |
<body> | |
<input class="autocaps" /> | |
<textarea class="autocaps"></textarea> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment