Here is my HTML snippet:
<html>
<head></head>
<javascript>
var item = document.getElementById('demo');
console.log(item);
var myList = document.getElementsByClassName('myClass');
for (var i=0; i<myList.length; i++) {
console.log(myList[i]);
}
</script>
<body>
<section>
<div class="needs_update">placeholder</div>
</section>
</body>
</html>
In addition, I have a variable that contains some JavaScript code:
let content = "document.querySelector('.selector').innerHTML = 'New Content'";
I want to replace the existing content inside the div with the class name needs_update
using the value from the JavaScript variable. How should I approach this?
The desired output after replacing should be:
<html>
<head></head>
<body>
<section>
document.querySelector('.selector').innerHTML = 'New Content';
</section>
</body>
</html>