You can listen out for the DOMSubtreeModified
event.
However, this doesn't sound like a good idea. You said:
Is there any way I can listen to the key events (like keyup, blur)?
You should use a call this code next to the code where you change the content of the span. Otherwise, you should be using an input element to listen out to the events you listed.
Here is an example using the DOMSubtreeModified
event:
const content = document.getElementById('content')
const append = () => content.innerText += ' change'
content.addEventListener('DOMSubtreeModified', () => console.log('change'))
<span id="content">Content</span>
<br>
<button onclick="append()">Change content</button>
Here are examples using change
(which acts similarly to blur
, but only triggers if there's a change) and keypress
events:
const content = document.getElementById('content')
content.addEventListener('change', () => console.log('change'))
content.addEventListener('keypress', () => console.log('keyPress'))
<input type="text" id="content" value="Content">