Capitalize first letter of the word (span)

How do I capitalize the first letter of the span tag? for instance, if I have the HTML code, how do I capitalize all the first letter of the span tag using javascript

<div id="Header">
  <h1>
    <img height="150" src="http://test.com/im.jpeg">
     <span>test</span> <span>test1</span> <span>test2</span>
  </h1>
</div>

you can do this with css

#Header span {
  text-transform:capitalize;
}
2 Likes

You can use span as a selector and use text-transform property for formating letters.


<style>
      span{
           text-transform:capitalize;
          }
</style>

I know this could be done with css. but i want to do it with javascript

Hey!

You can make a function like this:

function capitalize(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
}
1 Like

Hi,could you please tell me ,how to call the function in h1 tag