Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert text in Javascript contenteditable div

Tags:

People also ask

How do you use 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.

How do I make a div text editable?

Answer: Use the HTML5 contenteditable Attribute You can set the HTML5 contenteditable attribute with the value true (i.e. contentEditable="true" ) to make an element editable in HTML, such as <div> or <p> element.

How do I make a div not editable?

Try something like this: // Disable all input-like elements in the divs except for the last div $(". divclass:not(:last-child) :input"). attr("disabled", true);

How do you use Contenteditable in HTML?

Definition and UsageThe contenteditable attribute specifies whether the content of an element is editable or not. Note: When the contenteditable attribute is not set on an element, the element will inherit it from its parent.


Is there any way to insert a text (string, may or may not have html tags) to a div?

It has to be a div and not a textarea.

First of all, I need to get the cursor position, then insert the text in that position. It's similar to function insertAdjacentText, but it can only insert before or after a tag, and only works in IE.

Refer to this URL: http://yart.com.au/test/iframe.aspx. Note how you can position the cursor in the div, we need to add text at the cursor location.