Here I wanted to show you the flexibility of JQuery. Below is a HTML code that generates a grid with two rows and ten columns.
1 | <div id="container"> |
When the user double clicks on any of the cell, he can edit that content. The cell value get updated when user double clicks on any other cell.
1 | $(document).ready(function() { |
The above code does all the trick. First we hook the Double Click
event to all the DIV with class name column
using this $("#container .column").dblclick(function(){...});
Inside that, we dynamically add a textbox inside the DIV and set its text value as the HTML content of the parent DIV. And also we bind the blur
event of this texbox to a function, so that whenever the focus leaves from the textbox, that function is called. Then inside that function, we set the HTML content of the DIV with the Textbox value.
1 | $($editbox).bind("blur", function() { |
See the working demo below