Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute javascript function when div value changes

I have a div <div id="Country">India</div> . I want to execute some code (say JavaScript function) whenever the div value changes. How can I listen to changes on the div value? Do i need to use Jquery for this?

like image 308
Stunner Avatar asked Jan 22 '26 11:01

Stunner


1 Answers

an easy jquery solution is to use a custom event and trigger it yourself when you change the DOM:

$("#country").html('Germany').trigger('CountryChanged');


$('#country').on('CountryChanged', function(event, data) {
   //contentchanged
});
like image 79
Amine Hajyoussef Avatar answered Jan 25 '26 06:01

Amine Hajyoussef



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!