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

if (event.keyCode == 13) { 
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.