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">
    <img height="150" src="">
     <span>test</span> <span>test1</span> <span>test2</span>

you can do this with css

#Header span {

If you want to capitalize the span elements’ text, then @kruxor gave you an answer that might be what you are looking for. I was thinking you meant the actual letter of the tag like you wanted <Span>test</Span>.

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


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


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