Jump to content

enter key problem


alzami
 Share

Recommended Posts

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>
Link to comment
Share on other sites

There is basically 2 types of elements in HTML. block elements and flow elements. block elements can have pre-defined dimensions and will fully occupy a single row. Flow elements can have font sizes, alignment and other properties specific to text, plus multiple flow elements can exist on a single row.

 

Block elements can contain block and/or flow elements, but flow elements can only contain other flow elements. the <p> tag is the rare exception where as a block element, it can only contain flow elements, and the <br> tag is a block element. You could manually write in a <br> in a <p> tag, but it wouldn't be valid html.

 

so if you press enter, you should leave one paragraph tag and start a new one. If you would press enter again a br tag should automatically be added in-between the two p tags (if memory serves...)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...