JSFiddle - React, Tailwind, and code Playground
HTML
<div>
<p>There is some text here</p>
</div>
JavaScript
/*
* Use insertBefore to insert before :)
* Use appendChild to insert after
*/
(function(){
document.addEventListener("keydown", keyDownBody, false);
document.addEventListener("keydown", keyDownBody2, false);
function keyDownBody(e) {
var keyCode = e.keyCode;
if(keyCode==65) {
myFunction();
}
}
function myFunction()
{
var a = document.createElement("IMG");
a.src="https://unsplash.it/200/300";
document.body.appendChild(a,document.body.firstElementChild);
}
function keyDownBody2(e) {
var keyCode = e.keyCode;
if(keyCode==66) {
myFunctionb();
}
}
function myFunctionb()
{
var b = document.createElement("IMG");
b.src="https://unsplash.it/200/300";
document.body.insertBefore(b,document.body.firstElementChild);
}
})();