I am trying to optimize a code that is written in Javascript and other parts in Jquery. The question is simple, what is more efficient to create elements?
$(function(){
//OPCION 1
$('#myDiv').append('<button id="myBtn">Jquery</button>');
//OPCION 2
let btn = document.createElement('button');
btn.id = 'myBtn';
let txt = document.createTextNode('Javascript');
btn.appendChild(txt);
document.getElementById('myDiv').appendChild(btn);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="myDiv">
</div>
Welcome comments