JSFiddle - React, Tailwind, and code Playground
HTML
<div contenteditable="true">
div
<span>Test Span area</span>
div
</div>
CSS
div {
border: 1px solid red;
padding: 5px;
}
span {
background-color: #efefef;
}
JavaScript
function detect(){
if(document.selection){
//IE
alert(document.selection.createRange().parentElement().tagName);
}else{
// everyone else
alert(window.getSelection().anchorNode.parentNode.tagName);
}
}
$(function(){
$("div").keypress(function(){
detect();
});
});