JSFiddle - React, Tailwind, and code Playground
by pkysylevych
HTML
First name: <input id="txtFirstName" />
<br />
Surname: <input id="txtSurnameName" />
<input type="button" value="btnConvert" />
JavaScript
$.fn.capitalise = function() {
return this.each(function() {
var $this = $(this),
text = $this.text(),
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));
res.push(" "); // put space back in
}
$this.text(res.join(""));
});
};
$("#btnConvert").click(function(){
var fName = $("#txtFirstName");
var sName = $("#txtSurnameName");
});