2024-04-28 10:13:54 -04:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<style>
|
|
|
|
.democlass {
|
|
|
|
color: red;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<h1>Hello World</h1>
|
|
|
|
|
|
|
|
<p>Click the button to add a class attribute with the value of "democlass" to the h1 element.</p>
|
|
|
|
|
|
|
|
<button onclick="myFunction()">Try it</button>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
function myFunction() {
|
|
|
|
var before = document.getElementsByTagName("H1")[0].outerHTML;
|
2024-05-08 09:57:56 -04:00
|
|
|
console.assert(before === '<h1>Hello World</h1>', 'H1');
|
2024-04-28 10:13:54 -04:00
|
|
|
document.getElementsByTagName("H1")[0].setAttribute("class", "democlass");
|
|
|
|
var after = document.getElementsByTagName("H1")[0].outerHTML;
|
2024-05-08 09:57:56 -04:00
|
|
|
console.assert(after === '<h1 class="democlass">Hello World</h1>', 'H1 with class');
|
2024-04-28 10:13:54 -04:00
|
|
|
}
|
|
|
|
console.error("element.setAttribute.html");
|
|
|
|
myFunction();
|
2024-06-01 07:30:03 -04:00
|
|
|
console.exit();
|
2024-04-28 10:13:54 -04:00
|
|
|
</script>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|