Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
113
rated 0 times [  120] [ 7]  / answers: 1 / hits: 46262  / 13 Years ago, mon, august 1, 2011, 12:00:00

I have a contentEditable Div and I want remove any formatting especially for copy and paste text.


More From » jquery

 Answers
14

Have you tried using innerText?



ADDED:



If you want to strip markup from content pasted into the editable div, try the old hack of creating a temporary div -- see example below.



<!DOCTYPE html>
<html>

<head>
<meta http-equiv=Content-Type content=text/html; charset=utf-8 />
<title>Strip editable div markup</title>

<script type=text/javascript>
function strip(html) {
var tempDiv = document.createElement(DIV);
tempDiv.innerHTML = html;
return tempDiv.innerText;
}
</script>
</head>

<body>
<div id=editableDiv contentEditable=true></div>
<input type=button value=press onclick=alert(strip(document.getElementById('editableDiv').innerText)); />
</body>

</html>

[#90885] Saturday, July 30, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kylanalis

Total Points: 438
Total Questions: 85
Total Answers: 102

Location: Barbados
Member since Sun, Nov 27, 2022
1 Year ago
kylanalis questions
Sat, Oct 2, 21, 00:00, 3 Years ago
Tue, Oct 13, 20, 00:00, 4 Years ago
Thu, Feb 13, 20, 00:00, 4 Years ago
Tue, Jan 7, 20, 00:00, 4 Years ago
;