html – Make text capitalize

Question:

Can you tell me how to capitalize text? There is text on the site, but it is caps lock by default, you need to somehow capitalize it. Capitalize works when the text is initially small, but how to do the same when it is already large (the fact that it is large cannot be changed)

 p{ text-transform:capitalize!IMPORTANT; }
 <p> LOREM IPSUM </p>

Answer:

It is possible like this:

function titleCase(str) {
  var splitStr = str.toLowerCase().split(' ');
  for (var i = 0; i < splitStr.length; i++) {
    splitStr[i] = splitStr[i].charAt(0).toUpperCase() + splitStr[i].substring(1);
  }
  return splitStr.join(' ');
}

document.querySelector("p").textContent = titleCase(document.querySelector("p").textContent);
<p>LOREM IPSUM DOLOR SIT AMET</p>
Scroll to Top