I have a JQuery function
to Capitalize
the first alphabet of each word of a string.
Which is working fine.
The issue I am getting is, that, when I type any alphabet at the beginning of the word the cursor moves to the last alphabet of the string. If I type anything in between the cursor stays at it's place.
I searched and got some solutions but that where .jsp
or javascript
based. Looking for some simple JQuery
solution.
function pCase(strg) {
var str = strg;
str = str.toLowerCase().replace(/\b[a-z]/g, function(letter) {
return letter.toUpperCase();
});
return str;
}
function propCase(obj) {
obj.value = pCase(obj.value);
}
$(function() {
$(".properCase").on("keyup", function() {
propCase(this);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="banner-message">
<input type="text" class="properCase" />
</div>