I am trying to do a RTE where in i have a text embedded in a span element.I dont want the span tag to break when user hits enter on it. Here is what i have done

$(document).keydown(function(event){

if (event.keyCode==13)
{
var sel = document.getSelection();
var anchor_node = sel.anchorNode;
var parent_node = anchor_node.parentNode;

if (parent_node.nodeName == 'span' )
{
var range = sel.createRange();
range.moveElementToText(parent_node);
range.collapse(false);
range.select();
//now the cursor is out of span and hence shouldn't break it..
}
}

});
but it is not working.I am not sure whether this is possible.Basically what i am trying to do is to get the cursor out of span before when enter is pressed and hence assuming it will not break the span.Any comments?