<!DOCTYPE HTML>
<html>
<head>
<title>Interactive Web Page</title>
<link id="mycss" rel="stylesheet" href="mycss.css">
<script>
function resizeText(size) {
var styleSheet = document.getElementById('mycss').href;
if (styleSheet.style.fontSize == '2.0em') {
styleSheet.style.fontSize = parseFloat(styleSheet.style.fontSize) + (size * 0.2) + "em";
} else if (styleSheet.style.fontSize == '3.0em'){
styleSheet.style.fontSize = parseFloat(styleSheet.style.fontSize) + (size * 0.3) + "em";
}
}
</script>
</head>
<body id="theBody" class="theBod">
<h1 id="h1" onclick="clickChange();">Hello</h1>
<p id="para1" class="para1" onclick="resizeText(1);">Here is some text with a different size (click)<p>
<p id="para2" class="para2" onclick="resizeText(2)">More text with another size on click.<p>
<p id="demo" onclick="countToNum()"> Numbers (Click): </p>
</body>
</html>
I am creating a web page where the text size increases when an element is clicked based on the specified parameter in the onclick function. This functionality modifies content using an external stylesheet.
#para1 {
font-size: 2.0em;
}
#para2{
font-size: 3.0em;
}
The error message "Cannot read property 'fontSize' of undefined," keeps appearing, but I want the JavaScript to only enlarge the clicked element while keeping others unaffected. Any assistance would be highly appreciated as I struggle with JavaScript coding.