How to dynamically change table data with dynamically created element?
As sooon as I dblclick on table(3 Rows, 3 cols) data the input text appears on that <td> with dynamically allocated ID to that input.
As soon as I update text in that input and focusout or press enter from Input text the contents should be updated inside that <td> with that input text.
html:
- <div id="contentsTable" align="center">
- <table class="tblData">
- <tr class="tblRow">
- <td class="tblCol" id="td1">Item 1</td>
- <td class="tblCol" id="td2">Item 2</td>
- <td class="tblCol" id="td3">Item 3</td>
- </tr>
- <tr class="tblRow" id="td4">
- <td class="tblCol" id="td5">Item 4</td>
- <td class="tblCol" id="td6">Item 5</td>
- <td class="tblCol" id="td7">Item 6</td>
- </tr>
- <tr class="tblRow">
- <td class="tblCol" id="td8">Item 7</td>
- <td class="tblCol" id="td9">Item 8</td>
- <td class="tblCol" id="td10">Item 9</td>
- </tr>
- </table>
- </div>
js:
- $(document).ready(function() {
-
- });
- $(document).on('dblclick','.tblCol',function(){
- var itemText = $(this).text().toString();
- var id = $(this).attr('id');
- $(this).html("<input type=\"text\" id=txt"+id+" class=\"txtEdit\" value=\"\" size=\"15\" />");
- $('#txt'+id).focus();
- $('#txt'+id).val(itemText);
- $(this).unbind('dblclick');
- });
- $(document).on('focusout','.txtEdit',function(){
- var id=$(this).attr('id').toString().substring(3);
- alert('id :'+id);
- alert("Text val : "+$(this).val());
- alert(($(id).length)>0); //returning false
- alert($(id).html()); // error : undefined
- });
Hope you got what my problem is.
I want to know what I am doing wrong,
Thanks in advance...!