I am trying to create client side editable table. Here is my code. It works in Chrome, Firefox but not in IE. Is there anything more to do with script for IE?
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("td").click(function(){
if($(this).attr("contentEditable") == true){
$(this).attr("contentEditable","false");
} else {
$(this).attr("contentEditable","true");
}
})
});
</script>
<p>
<table id='transitTable' border="1" cellspacing="2" cellpadding="2" class='display' width="400">
<tr id='1'>
<td >H1</td>
<td >H2</td>
<td >H3</td>
<td >H4</td></tr>
<tr id='2'>
<td >R1</td>
<td >R1</td>
<td >R1</td>
<td >R1</td></tr>
<tr id='3'>
<td >R2</td>
<td >R2</td>
<td >R2</td>
<td>R2</td></tr></table></p>
There are many elements in IE, which can't have contenteditable
set directly. However, you can wrap the whole table
into a content editable div
.
<div contenteditable="true">
<table>
...
</table>
</div>
This will make all the cells in the table editable. Though in some browsers (FF) the view will be a bit messy due to the shown editing handles of the table.
Another possibility is to add for example a content editable span
or div
to each td
.