hankknight
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>
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
OR
$(document).ready(function() {
$('h1').each(function() {
$(this).replaceWith('<h2>'+$(this).html()+'</h2>');
});
});
yep would just depend on how much control you want over the elements
http://api.jquery.com/replaceWith/