1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Rep Power

    Avoid span break when enter key is hit on it

    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


    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();
    //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?
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Rep Power
    Try using onkeydown and onkeyup; inside the "Enter" keycode condition; when validating the parent_node.nodeName and see if you can move cursor, beyond span; based on nested keypress events. That might be one possible way to go with this.

IMN logo majestic logo threadwatch logo seochat tools logo