JavaScript Detect variable change with jquery detect variable change javascript,detect variable change angular 6,detect

I make an AJAX call to my server to read a file and get the value back as response. If the request was successful then i replace the innerHTML from my <p> element with id output with the response value. Now I try to fire an alert every time if the value has changed. I tried to add an event to my <p> element so I can detect if the variable has changed and fire my function:

<p id="output"></p>

<script>
    $("#output").change(function() {
        alert("HELLO WORLD!");
    });
</script>

There is no alert() showing up.

Answer:1

Changing the text/HTML value of an element doesn't raise an event. You would need to trigger one manually. For example:

// in the $.ajax success handler:
$('#output').trigger('contentchanged');

// event handler
$("#output").on('contentchanged', function() {
    alert("HELLO WORLD!");
});

You could also use a Mutation Observer for this, but note they are not supported in older browsers, such as IE10 and lower.

Answer:2

I have modified a simple nfc on-detect, to send a simple byte array over in an separate cordova app using chariotstudios-nfc-plugin . The code is shown below. index.js var app = { // Application ...

I have modified a simple nfc on-detect, to send a simple byte array over in an separate cordova app using chariotstudios-nfc-plugin . The code is shown below. index.js var app = { // Application ...

I have an array arr = [ [1,2,3], [4,5,6], [7,8,9] ] I want to remove the array that contains the element 4. Here it would remove 4,5,6. So it'd be arr = [[1,2,3],[7,8,9]]; I tried a for loop but I ...

I have an array arr = [ [1,2,3], [4,5,6], [7,8,9] ] I want to remove the array that contains the element 4. Here it would remove 4,5,6. So it'd be arr = [[1,2,3],[7,8,9]]; I tried a for loop but I ...

  1. remove certain values from list python
  2. remove certain values in r
  3. remove certain values from a list in r
  4. remove certain values from array matlab
  5. remove certain values from vector r
  6. remove certain values from dictionary python
  7. remove certain values from dataframe
  8. remove certain values from array python
  9. remove certain values from list excel
  10. remove certain values from array js
  11. remove certain values from array vba
  12. remove certain values from data frame r
  13. remove certain values from vector matlab
  14. remove certain values from column in r
  15. remove certain values from excel
  16. remove certain values from array php
  17. remove certain values from numpy array
  18. remove certain values pandas
  19. remove certain values from pivot table
  20. remove certain values from excel column

I've got a small problem which has to do with the following approach: I want to iterate through a given array of URLs with a loop I do this here because I want to measure the loading time of each ...

I've got a small problem which has to do with the following approach: I want to iterate through a given array of URLs with a loop I do this here because I want to measure the loading time of each ...

  1. casperjs page.resource.received

I want to toggle the image using if-else but it didn't work, can someone please explain what is wrong with the code. <img src="img/somepic.jpg" id="pic"><br/> <a href="javascript:...

I want to toggle the image using if-else but it didn't work, can someone please explain what is wrong with the code. <img src="img/somepic.jpg" id="pic"><br/> <a href="javascript:...