Created
March 12, 2012 23:03
-
-
Save alex-gist/2025270 to your computer and use it in GitHub Desktop.
jQuery: Capitalize first letter while typing inside input field
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
<script type="text/javascript" charset="utf-8"> | |
//Capitalize first letter while typing in side of input field | |
jQuery(document).ready(function($) { | |
$('#selector').keyup(function(event) { | |
var textBox = event.target; | |
var start = textBox.selectionStart; | |
var end = textBox.selectionEnd; | |
textBox.value = textBox.value.charAt(0).toUpperCase() + textBox.value.slice(1); | |
textBox.setSelectionRange(start, end); | |
}); | |
}); | |
</script> |
Thanks this was useful. Any idea how to capitalize the first letter of all words in an input field?
@bryanwillis <input class="capital"></input>
Then just put this in your css .capital{text-transform: capitalize;}
Thanks this was useful for me
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/2025270.git