JSFiddle - React, Tailwind, and code Playground
by pkysylevych
HTML
First name: <input type="text" id="txtFirstName" value="this IS jUST a TESt" />
<br />
<input type="button" id="btnConvert" value="Convert" />
JavaScript
$.fn.capitalise = function() {
return this.each(function() {
var $this = $(this),
text = $this.val(),
split = text.split(" "),
res = [],
i,
len,
component;
for (i = 0, len = split.length; i < len; i++) {
component = split[i];
res.push(component.substring(0, 1).toUpperCase());
res.push(component.substring(1).toLowerCase());
res.push(" "); // put space back in
}
$this.val(res.join(""));
});
};
$("#btnConvert").click(function(){
$("#txtFirstName").capitalise();
});