innerHTML and Firefox

Discussion in 'JavaScript' started by nonapp, Dec 23, 2009.

  1. #1
    When you change the the contents of a div's text with innerHTML in Firefox the cursor behaves strangely. After I change the innerHTML of a div to a new text value the cursor moves to the left of the beginning of the text. Other browsers move the cursor to the right of the end of text.

    Is there a way to move the cursor or change its behavior and place the cursor to the right of the end of text after I alter the innerHTML value? I tried using setSelectionRange(start, end) and that did not work.
     
    nonapp, Dec 23, 2009 IP
  2. avkluki

    avkluki Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Does the value you assign contains other tags ? If yes then it's better do not use innerHTML, many browsers work incorrect in that case. More reliable to create and attach elements to the tree manually.
     
    avkluki, Dec 24, 2009 IP
  3. nonapp

    nonapp Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I strip the html from all input before I insert it into the div. How could I change the behavior in firefox? I want the cursor always to be at the right of newly added text in a div.
     
    nonapp, Dec 24, 2009 IP