Link to home
Create AccountLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

jQuery: Convert h2 tags to h1 tags

Using jQuery, how can I convert all h2 tags to h1 tags?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Demo</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<style type="text/css">
h1 {color: red;}
h2 {color: blue;}
</style>
</head> 
<body> 

 <h1>Hello</h1>
 <h2>Word</h2>
 <h2>Testing</h2>
 <h2>123</h2>


<script type="text/javascript"> 

// convert all h2 tags to h1 tags

</script> 

</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Rob
Rob
Flag of Australia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
OR

$(document).ready(function() {
       $('h1').each(function() {
       $(this).replaceWith('<h2>'+$(this).html()+'</h2>');
    });
 });

Open in new window

yep would just depend on how much control you want over the elements