Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@alex-gist
Created March 12, 2012 23:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alex-gist/2025270 to your computer and use it in GitHub Desktop.
Save alex-gist/2025270 to your computer and use it in GitHub Desktop.
jQuery: Capitalize first letter while typing inside input field
<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>
@chasitywilliams
Copy link

@bryanwillis
Copy link

Thanks this was useful. Any idea how to capitalize the first letter of all words in an input field?

@Ahors
Copy link

Ahors commented May 6, 2018

@bryanwillis <input class="capital"></input> Then just put this in your css .capital{text-transform: capitalize;}

@jaykumharprajapat
Copy link

Thanks this was useful for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment