0

The problem is that if I focus on the childOfroot element and press a key, the element triggered is it's parent yet it is supposed to be itself.

function test(event, element) {
  console.log($(element).attr('id'))
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<span id="root" contenteditable="true" onkeyup="test(event, this)">
  This is changable
  <span contenteditable="true" onkeyup="test(event, this)" id="childOfroot"> | including this</span>
</span>

See demo here: https://jsfiddle.net/s36L8bpj/

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
whocaresz
  • 17
  • 4

1 Answers1

0

For those who is having the same problem, apparently you cant send the element own event if the parent element have contenteditable="true".

So I changed my structure to below:

<span id="root" contenteditable="false" >
 <span contenteditable="true" onkeyup="test(event, this)" id="childOfroot0">This is changable
 <span contenteditable="true" onkeyup="test(event, this)" id="childOfroot1"> | including this</span>
</span>

Peace be upon you :)

whocaresz
  • 17
  • 4