0

I have a code in which i am changes a tag's inner text with js but i want that tag to call a function when it is changes, i dont know why i doesn't call to the function when it is changes please help.Sorry for my bad english. This is an example of what i am trying to achieve :

<!DOCTYPE html>
<html>
<body>

<h1 id="result"></h1>

<p id="demo" onchange="myFunction()">Click button to change my HTML content</p>

<button id="press" onclick="changeText()">button</button>

<script>
function changeText() {
  document.getElementById("demo").innerText = "hhhhhhhhhh";
}
function myFunction() {
  document.getElementById("result").innerText = "Text changed!";
}

</script>

</body>
</html> 
  • If you know everywhere that will change the content, you could just call `myFunction()` from inside `changeText()` If this is just an example and you actually don't control the function making the changes, it would be worth mentioning that in the question. – DBS Jul 29 '22 at 09:52
  • The `change` event is only available on form (``, ` – Andreas Jul 29 '22 at 09:53
  • https://stackoverflow.com/questions/6676186/use-onchange-in-a-div – Lucas Bodin Jul 29 '22 at 09:54

0 Answers0