For assignment, I cannot touch HTML code and edit an external JS file. I need to pass the code to an existing class and turn it into a button to run the script.
When loading, it is necessary to start the conversion of the element with the specified idbutton, which can also trigger the function when pressed.
So let's say we have id="bar"how to do this?
My code doesn't work at all.
document.getElementById("bar").onload = function () { myFunction() };
function myFunction() {
document.getElementById("bar").innerHTML = "<button></button>";
}
source
share