The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

contentEditable newline question.

I'm creating a little WYSIWYG HTML editor, like the one I'm using to type this post...

problem is... when I use a div or span with the contentEditable property set, it works just about perfectly except that when you press enter it creates a <p> instead of a <br>, which looks like crap since its a far larger break than I would like... i got over this by using a little function

Code:

if (event.keyCode == 13) {
editor.innerHTML+='<br>'
}

that works fine, except that now, when I press enter somwhere in the middel of some text, it jumps to the end of the text and inserts it there. I can see my problem, but I'm having a bit of a problem solving it.

how would I get the position of the cursor and insert the linebreak there?

or am I going about this the wrong way?
any help would be apreciated.

thanx

Spartan
---------------------
It's like our sergeant told us before one trip into the jungle. Men! Fifty of you are leaving on a mission. Twenty-five of you ain't coming back.
-Mr.Payne