<html>
</head>
<body>
<div class="class1">
<p>text to update1</p>
<p>text to update2</p>
<p> </p>
</div>
<div class="class2">
<p>text to update1</p>
<p>text to update2</p>
<p> </p>
</div>
<button onclick="obj1.changeContent()">changeContent</button>
<script type="text/javascript">
var change= function()
{
}
change.prototype.changeContent=function()
{
// target specific element positions
var paragraph=document.getElementsByClassName("class1");
paragraph[0].innerHTML="hello";
paragraph[1].innerHTML="world";
var addthem = paragraph[2].innerHTML = second;
}
var obj1= new change;
</script>
</body>
When attempting the above process, I encountered an issue:
Uncaught TypeError: Cannot set property 'innerHTML' of undefined
This error occurs when trying to modify the innerHTML property of the second paragraph [1] element in the first class (Class1). How should I progress from here?