Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make clickable anchor in contentEditable div?

I have following code:

<div contentEditable="true">     Blah blah <a href="http://google.com">Google</a> Blah blah </div> 

Fiddle

Is there a way to make this a clickable, not editable, without moving anchor outside that div?

like image 737
Infinity Avatar asked Aug 21 '12 16:08

Infinity


People also ask

How do you make a div Contenteditable?

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.

What is Contenteditable div?

Definition and Usage The contenteditable attribute specifies whether the content of an element is editable or not.

What is the HTML attribute Contenteditable used for?

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.

How do I turn off Contenteditable div?

Just set contentEditable="false" . See this answer.


2 Answers

Just wrap the link in another div, like so:

<div contentEditable="true">      <div contentEditable="false">             Bla bla <a href="http://google.com">Google</a> Bla bla     </div> </div>​ 
like image 177
Forty-Two Avatar answered Oct 09 '22 07:10

Forty-Two


Make the link itself uneditable (works at least on HTML5):

<a contenteditable="false" href="http....... >

like image 40
Shmulika Avatar answered Oct 09 '22 06:10

Shmulika