Page 182 - Computer Software Application TP - Volume 1
P. 182
COMPUTER SOFTWARE APPLICATION - CITS
box2.style.backgroundColor = ‘green’;
box2.style.color = ‘white’;
box2.style.border = ‘2px solid white’;
</script>
</body>
</html>
3 Save the program as a .html file
4 Open the html file with a web browser
5 Verify the output.
TASK 10 : creates a <style> element dynamically and appends it to the document
1 Open the text editor
2 Write the following codes
<html>
<head>
<meta charset=”UTF-8”>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0”>
<title>Creating a Style Element</title>
</head>
<body>
<div id=”content”>This text will be styled.</div>
<script>
// Create a style element
const styleElement = document.createElement(‘style’);
// Define your CSS rules
const cssRules = `
#content {
color: blue;
font-size: 20px;
font-weight: bold;
167
CITS : IT & ITES - Computer Software Application - Exercise 44