SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    Jun 2006
    Location
    Durban, South Africa
    Posts
    287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Insert space dynamically

    Hi all

    I have some tabs on my page. As someone clicks on the different tabs, I need to update the content. Simple enough, except that I cant insert spaces.

    Here is some code

    Code:
      var space = document.createTextNode(" ");
    
      document.getElementById("the_body").appendChild(space);
    It literally inserts   in the "the_body" tag.

    Does anyone know what I can do here?
    Thanks in advance

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    var space = document.createTextNode("\ua0");
    Entity references are parsed by the HTML parser as the page loads. You can't insert them with JavaScript like that. So you insert the literal non-breaking space character instead (U+00A0).
    Last edited by AutisticCuckoo; May 6, 2008 at 04:01.
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Addict
    Join Date
    Jun 2006
    Location
    Durban, South Africa
    Posts
    287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would love to say that this worked, but unfortunately it didnt :'(
    I just get a browser error and this message

    line: 154
    Char: 1
    Error: Object expected
    Code: 0
    URL: http://localhost

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could be because I made a typo (createTextNoode instead of createTextNode).
    Birnam wood is come to Dunsinane

  5. #5
    SitePoint Addict
    Join Date
    Jun 2006
    Location
    Durban, South Africa
    Posts
    287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ooops I forgot to write that in my last post, I picked up on the typo and corrected it Unfortunately correcting the typo didnt help...

  6. #6
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just did a quick test of my own, and it look as if you have to specify four digits in the escape:
    Code:
    var space = document.createTextNode("\u00a0");
    Works in Opera 9.27, Firefox 2.0 and IE6 on Windows XP.
    Birnam wood is come to Dunsinane

  7. #7
    SitePoint Addict
    Join Date
    Jun 2006
    Location
    Durban, South Africa
    Posts
    287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Awesome bro!
    Thanks for all your help so far
    You've made this un-bearable day filled with errors slightyl better
    Cheers


Bookmarks

Posting Permissions

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