JSFiddle - React, Tailwind, and code Playground
HTML
<div><input type="button" /></div>
<section></section>
CSS
input { display: block; width: 100%; border: 3px solid black; }
div > input { background: blue; }
section > input { background: orange; }
JavaScript
var div = document.querySelector('div')
var inp = document.querySelector('input')
var sec = document.querySelector('section')
inp.onclick = function(e) {
if(this.parentElement == div) {
sec.appendChild(this);
} else {
div.appendChild(this);
}
}
div.onclick = function() {
alert('div');
}
sec.onclick = function() {
alert('sec');
}