Detect text change on a jquery td

0

I need to detect the changes made in the td of my table sending an alert, greetings thanks.

setTimeout(function(){
$('td[name$=total]').text("12345");
}, 3000);//hago el cambio en todos los td al pasar cierto tiempo

//busco todos los td que terminen con el nombre total
$('td[name$=total]').on(function(){

alert('el codigo ha cambiado');
});//necesito detectar el cambio en el td mandando un alert en una funcion onchange
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>

<table id="table">
  <thead>
    <tr>
      <th>Codigo</th>
      <th>Cantidad</th>
    </tr>
  </thead>
  <tbody>
    <tr id="1"><!-- tabla se contruye dinamica-->
      <td name="TjnDT78BQtotal">4859</td>
      <td>2</td>
    </tr>
    <tr id="2">
      <td name="KT78df8DKtotal">2568</td>
      <td>4</td>
    </tr>
    <tr id="3">
      <td name="TjnDTjgBQtotal">4859</td>
      <td>5</td>
    </tr>
    <tr id="4">
      <td name="CT77gfjkKtotal">2568</td>
      <td>1</td>
    </tr>
  </tbody>
</table>
    
asked by Javier Antonio Aguayo Aguilar 27.11.2017 в 14:46
source

1 answer

2

To achieve what you want, you should simply assign the event DOMSubtreeModified to <td> that require it. You must bear in mind that the event onchange colo works for form elements ( input , select , textarea , checked , etc).

Here is an example of a functional code:

setTimeout(function(){
$('td[name$=total]').text("12345");
}, 3000);//hago el cambio en todos los td al pasar cierto tiempo

//busco todos los td que terminen con el nombre total
$('td[name$=total]').one("DOMSubtreeModified", function(){
   alert('el codigo ha cambiado');
});//necesito detectar el cambio en el td mandando un alert en una funcion onchange
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>

<table id="table">
  <thead>
    <tr>
      <th>Codigo</th>
      <th>Cantidad</th>
    </tr>
  </thead>
  <tbody>
    <tr id="1"><!-- tabla se contruye dinamica-->
      <td name="TjnDT78BQtotal">4859</td>
      <td>2</td>
    </tr>
    <tr id="2">
      <td name="KT78df8DKtotal">2568</td>
      <td>4</td>
    </tr>
    <tr id="3">
      <td name="TjnDTjgBQtotal">4859</td>
      <td>5</td>
    </tr>
    <tr id="4">
      <td name="CT77gfjkKtotal">2568</td>
      <td>1</td>
    </tr>
  </tbody>
</table>
    
answered by 27.11.2017 в 15:10