Your last code did not work because you are not inserting the element created on your page, besides not escaping the " (quotation marks) of attributes.
You can also use insertAdjacentHTML to 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 in place of position
beforebegin: Before the Element
afterbegin: Inside the element and before your first child
beforeend: Inside the element and after your last child
afterend: After the element
// 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>
<div id="target"></div>
By the console? It wouldn’t be by javascript?
– adventistaam