0

I am trying to show to alert When a row of my table is modified but esta not work. Here my code . Thanks!

      $(document).ready(function(){
    $("#table").change(function(){
        alert("The text has been changed.");
    });
});
<table border="3" id='table' >
<thead>
<tr>Heading 1</tr>
<tr>Heading 2</tr>
</thead>
<tbody>
<tr>
<td contenteditable='true' id='bebe'>a</td>
<td contenteditable='true'>a</td>
</tr>
<tr>
<td contenteditable='true'>a</td>
<td contenteditable='true'>a</td>
</tr>
</tbody>
</table>
Annon
  • 109
  • 1
  • 2
  • 14
  • You need to specify in your question what is changing. Are rows being added/removed? Is the content of a `` changing? A `` doesn't know how to react to a change event.
    – adam-beck Aug 18 '16 at 19:50
  • From the jquery docs: This [change()] event is limited to elements, – adam-beck Aug 18 '16 at 19:50
  • DataTables plugin? – AnasSafi Aug 18 '16 at 19:51
  • This will check for text change [jsFiddle](https://jsfiddle.net/dff5mqkc/2/) and not with each keypress because it'd be a mess if the user is going to enter more than one character – Mi-Creativity Aug 18 '16 at 20:03

1 Answers1

1

UPDATED This is when you want to check whenever the user pres a key in their keyboard

 $(document).ready(function(){ 
    var val1;
    var val;
        $("#table tbody tr td").on('keypress',function(){
                val = $(this).text();
            //alert(val);
        });
        $("#table tbody tr td").keyup(function(){
            val1 = $(this).text();
            if(val1!=val){
                    alert("text has changed");
            }
        });
    });

This is if you want to trigger only when user leaves the box

$(document).ready(function(){ 
var val1;
var val;
    $("#table tbody tr td").on('focus',function(){
            val = $(this).text();
        //alert(val);
    });
    $("#table tbody tr td").focusout(function(){
        val1 = $(this).text();
        if(val1!=val){
                alert("text has changed");
        }
    });
});
Edison Biba
  • 4,384
  • 3
  • 17
  • 33