Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

contenteditable not working in IE 10

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>
like image 455
Aakash Doshi Avatar asked Aug 22 '13 13:08

Aakash Doshi


People also ask

How do I make my page Contenteditable?

To edit the content in HTML, we will use contenteditable attribute. The contenteditable is used to specify whether the element's content is editable by the user or not. This attribute has two values. true: If the value of the contenteditable attribute is set to true then the element is editable.

How do I make Contenteditable in Javascript?

You can add the contenteditable="true" HTML attribute to the element (a <div> for example) that you want to be editable. If you're anticipating a user to only update a word or two within a paragraph, then you could make a <p> itself editable.

Is Contenteditable angular?

Angular does not have an accessor for contenteditable , so if you want to use it with forms you will have to write one.

What does Contenteditable attribute do?

The contenteditable global attribute is an enumerated attribute indicating if the element should be editable by the user. If so, the browser modifies its widget to allow editing.


2 Answers

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.

like image 105
Teemu Avatar answered Oct 13 '22 01:10

Teemu


IE is not response contenteditable inside td tag.

You can try:

<td id="my-content" class="editable">
    <div contentEditable="true" style="width: 100%; height: 100%;">
        ...
    </div>
</td>
like image 31
Suwarnakumar Kanapathipillai Avatar answered Oct 13 '22 01:10

Suwarnakumar Kanapathipillai