www.webdeveloper.com
Results 1 to 4 of 4

Thread: document.createTextNode with a " " (space) causes thrashing in browser

Hybrid View

  1. #1
    Join Date
    Oct 2012
    Posts
    1

    document.createTextNode with a " " (space) causes thrashing in browser

    Hi,

    This is my first post so thanks for your help and patience Iím a server-side dev and am picking up some client side javascript for the first time so really Iím a newbie.

    Here's the code snippet:

    _______________________________________
    // create free number
    var free_text_span = document.createElement("SPAN");
    free_text_span.className = this.CSS_NUMBER_FREE_TEXT_SPAN;
    free_text_span.appendChild(document.createTextNode(" " + freeNumberText + " "));
    highlightTextAreaElement.appendChild(free_text_span);
    _______________________________________

    The problem is the ď ď result in the screen blinking and then CPU going up to 100%.

    If I remove the spaces there is no thrashing and all is well (but I need the spaces there):

    _______________________________________
    free_text_span.appendChild(document.createTextNode(freeNumberText));
    _______________________________________

    Iíve tried to use innerHTML without success, but this could be user error:

    _______________________________________
    // create free number
    var free_text_span = document.createElement("SPAN");
    free_text_span.className = this.CSS_NUMBER_FREE_TEXT_SPAN;
    free_text_span.innerHTML = " " + freeNumberText " ";
    highlightTextAreaElement.appendChild(free_text_span);
    _______________________________________

    Iíd really appreciate someone to point out where Iím going wrong.

    Many thanks,
    Mick

  2. #2
    Join Date
    Nov 2010
    Posts
    1,083
    weird. I've never had a problem with that. I don't have time to check it out, but in the meantime have you tried
    Code:
    free_text_span.innerHTML = " " + freeNumberText " ";

  3. #3
    Join Date
    Jan 2010
    Posts
    77
    You might find that the JavaScript Octal Hex or Unicode special characters might work
    Code:
    octal
    free_text_span.appendChild(document.createTextNode("\240"+freeNumberText+"\240"))
    
    hex 
    free_text_span.appendChild(document.createTextNode("\xA0"+freeNumberText+"\xA0"))
    
    Unicode
    free_text_span.appendChild(document.createTextNode("\u00A0"+freeNumberText+"\u00A0"))

  4. #4
    Join Date
    Jan 2011
    Posts
    117
    free_text_span.appendChild( document.createTextNode(" " + freeNumberText + " ") )
    should work just fine

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles