I'd like everytime the user click over the #box div to focus within the #innerbox contenteditable.
I'm using the following code, but it only works once:
document.getElementById('box').addEventListener('click', function(){
setTimeout(function() {
document.getElementById('innerbox').focus();
}, 0);
});
#innerbox{
border: 1px solid;
}
#box{
border: 1px blue solid;
padding:20px;
}
<div id="box">
<div id="innerbox" contenteditable="true" style="min-height:26px;" onkeyup="myFunction()"></div>
</div>
there are no other 'click' listeners on the #box
EDIT: A difference i have with the snippet above is that the #innerbox div gets removed and recreated in the DOM, and it's after it gets recreated the first time that click eventlistener doesn't work anymore, can this be the issue?
EDIT 2: I tried using
$('#box').on('click', '#innerbox', function(){
$('#innerbox').focus();
});
for dynamically created elements but also doesn't work.