Jarosław Chudzik
Jarosław Chudzik

Reputation: 33

Adding content (including iframes) via innerHTML is incomplete

Create simple page that loading into div some content by innerHTML, but when i use this javascript:

document.getElementById("someDiv").innerHTML = 
   '<iframe id="test1" class="yt-embed " style="top: 50px; width: 98%; height: 80%; margin-left: 1%;" src="https://www.youtube.com/embed/R7Ui_FnOPh8?rel=0&amp;enablejsapi=1" allowfullscreen="false" frameborder="0" /><br>TEST';

But everything after iframe is not added. Does anyone know why this is so?

Upvotes: 0

Views: 82

Answers (1)

Scott Marcus
Scott Marcus

Reputation: 65806

An iframe cannot be self-terminated as in: <iframe />. You must provide an explicit closing tag for the element:

 
       <iframe id="test1" class="yt-embed " style="top: 50px; width: 98%; height: 80%; margin-left: 1%;" src="https://www.youtube.com/embed/R7Ui_FnOPh8?rel=0&amp;enablejsapi=1" allowfullscreen="false" frameborder="0"></iframe><br>TEST

Upvotes: 1

Related Questions