I have a situation where I need to import external content into a dom element, then take that input and inject it into a different dom element. However, it must be done without any library.
The content can be a mix of script tags, a tags, iframes etc...
In the following example I'm saving the external content into the text area element, then use the append method of jQuery and saves it into the container, which results in the execution of the script and the addition of the anchor element to the container div.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<textarea style="display:none" id ="thirdParty">
<a href="http://www.google.com">
test
</a>
<script>
alert("3rd party content");
</script>
</textarea>
<div id="container">
</div>
<button onclick="inject()">
Test
</button>
<script>
function inject() {
$('#container').append(document.getElementById('thirdParty').value);
}
</script>
</body>
Is there anyway to recieve the same result without the usage of jQuery?