So, I created this:
https://codepen.io/Blvcksquid/pen/yLpdBoO
Now I want a js function thats assigned to the onclick button function "schach()". The function should change the "box" element on click to an iframe element with the url "schach.coach".
I tried to write the function on my own, but the variable doesnt work:
function schach() {
let content = " <iframe class="box2" src="https://schach.coach" style="border:3px #black solid"; name="myiFrame" scrolling="yes" frameborder='1' marginheight="0px" marginwidth="0px" height="450px" width="240px" allowfullscreen></iframe>"
document.getElementById("box").innerHTML = "content"
}
I am sure something's wrong with my content variable or am I even using the wrong function? Please help, I am a beginner and hungry to learn.
It looks like you are assigning a string to the box instead of the actual content of the variable. Try this line instead:
document.getElementById('box').innerHTML = content;
Notice that I have removed the double quotes from the word "content"