Search code examples
javascripthtmlonchange

Use onchange in a div


Is it possible to use onchange event in a <div>?

Because my <div> changes its text inside.

Can I do something like this?

<div id="name" onchange="calculateTotal();"></div> 

Solution

  • Since you say you're using AJAX, why not execute the function when you update the text. I'm not sure if you use any library, but in case it's jQuery just do:

     $.ajax({ ...,
              success: function() {
                   ... other things ...
                   ... setting div text ...
                   calculateTotal();
              }
           });