Your last code did not work because you are not inserting the element created in your page, and you are not escaping the "(quotation marks) of the attributes.
You can also use insertAdjacentHTML for insert an HTML code into your page.
element.insertAdjacentHTML("posição", "código-html);
To control where you want the element, simply add one of the values below instead of position
Beforebegin: Before Element
afterbegin: Inside the element and before your first child
beforeend: Inside the element and after your last child
afterend: After the
// Captura o elemento onde queremos adicionar
var target = document.querySelector('#target');
// Código do iframe
var elemento = '<iframe frameborder="0" id="novo-iframe" src="/"></iframe>';
// Adicionamos o iframe dentro do elemento capturado
target.insertAdjacentHTML('beforeend', elemento);
// Exibidos o código do iframe criado no console
console.log(document.getElementById('novo-iframe'));
iframe {
height: 14em;
width: 100%
}
<div id="target"></div>
With jQuery
$('#target').append('<iframe frameborder="0" id="novo-iframe" src="/"></iframe>');
iframe {
height: 14em;
width: 100%
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divid="target"></div>