0

i am trying to learn how to make a text editor.here i creat a paragraph using "para" button.and inside the paragraph there will be a quote.Every time I press 'enter' within this paragraph, a new paragraph is created, rather than a line break tag (<br>). How can I force a line break tag to be created instead of a paragraph element?also

i cant even get outside of the quote tag.though designMode is on and contenteditable is true for both paragrap and quote

<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style>
*{margin:0px;padding:0px;}

#idContent{
    background-color:pink;
}
div{
    border:1px solid black;
}
</style>
</head>

<body onLoad="loads();" style="position:relative;">
<iframe id="idContent" width="600" height="280" contenteditable="true" ></iframe>
<input type="button" value="para" onClick="para();">

<script>
function loads(){
    idContent.document.designMode="On";
}
function para(){

    var m=document.createElement("p");

m.setAttribute('style',"border:1px solid black;height:100px;width:500px;position:relative;background-color:white;");
m.setAttribute('designMode',"on");
m.setAttribute('contenteditable',"true");

    var t=document.createElement("q");
    t.innerHTML="quote here";
    t.setAttribute('designMode',"on");
    t.setAttribute('contenteditable',"true");
    m.appendChild(t);
    idContent.document.body.appendChild(m);

}
</script>
</body>
</html>
3
Contributors
4
Replies
27
Views
3 Years
Discussion Span
Last Post by Troy III
1

I do not convert it to <br>, because when user again try to edit html code, It will show <br> in the content itself.

So rather I used to display content when its not in textarea, using nl2br function.

<?php $content ="your saved data";?>

<textarea > <?php echo $content;  </textarea>

<div > <?php echo nl2br($content);  </div>

Edited by urtrivedi

Votes + Comments
nice one
0

thanks.i don't understand your php codes because i haven't learned php yet.i am concentrating on js currently.

0

Every time I press 'enter' within this paragraph, a new paragraph is created, rather than a line break tag (<br>). How can I force a line break tag to be created instead of a paragraph element?

Have you tried SHIFT+Enter for a new line instead of a new paragraph?

0

Have you tried SHIFT+Enter for a new line instead of a new paragraph?

I think you have but you are embarrased to come back and mark the thread solved.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.