Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Make all headings toUpperCase(); without using id:s.

What I have tried:

HTML
<!DOCTYPE html>

<p>Convert string to upper case:</p>

Try it
<h1> Hello World!</h1>
<h2> Hello World!</h2>
<h2> Hello World!</h2>
<h2> Hello World!</h2>


function myFunction() {
    var text = document.querySelectorAll("h1, h2").innerHTML;
    document.querySelectorAll("h1, h2") = text.toUpperCase();
}
Posted
Updated 30-May-18 17:51pm
v2

1 solution

There are couple way to do it.
1. Through JavaScript. Note that querySelectorAll return list of elements, therefore a loop is required to iterate all the elements in it.

JavaScript
function myFunction() {  
    document.querySelectorAll('h1, h2').forEach(function(tag) {
      tag.innerHTML = tag.innerHTML.toUpperCase();
	}); 
}

myFunction() ;


2. CSS
CSS
h1, h2 {
  text-transform: uppercase;
}


CP_upper case - JSFiddle[^]
 
Share this answer
 
Comments
Karthik_Mahalingam 31-May-18 5:13am    
5
Bryian Tan 31-May-18 16:15pm    
thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900