Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts

    Question createTextNode for special characters

    document.createTextNode('·sometext')
    or
    document.createTextNode('\&middot\;sometext')

    returns exactly ·sometext as string...

    Any ideea how to create special characters in textNode?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #2
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    	<head>
    		<title>52522</title>
    	</head>
    	<body>
    		<script type="text/javascript">
    			var txt = document.createTextNode("This is a &middot; entity: " + String.fromCharCode(183));
    			document.body.appendChild(txt);
    		</script>
    	</body>
    </html>

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Thanks.
    Yes, even an unicode solution could be used. Till than I confess I have used a rather unelegant solution, such as:

    var oTxt = document.createTextNode('sometext');
    oTxt.innerHTML = 'specialchar'+oTxt.innerHTML;
    Last edited by Kor; 02-17-2005 at 09:20 AM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    The most elegant solution would probably be to use a UCS-2 JavaScript escape - \uxxxx inside the string you send to createTextnode, where x is a hexadecimal digit.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #5
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Yes, thanks, I have found till the end an unicode solution such as:

    document.createTextNode('\u00B7sometext');
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #6
    Regular Coder
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts

  • #7
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Thanks. This is quite an old thread of mine (over 1 year) I have learned since then how to use unicode escapes... Thanks anyway...
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #8
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,991
    Thanks
    120
    Thanked 76 Times in 76 Posts
    readed all the post above, but cant figure out how to solwe this without innerHTML



    Code:
    //lest say taht arrElements[i] contains "TEST" 
    
    // does not work i.e returns '&nbsp;TEST'
    someNode.appendChild(document.createTextNode("&nbsp;" + arrElements[i])); 
    
    //has no effest i.e returns 'TEST'
    someNode.appendChild(document.createTextNode(" " + arrElements[i]));
    thanks for tips

  • #9
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,991
    Thanks
    120
    Thanked 76 Times in 76 Posts
    did some googling, this works:

    Code:
    someNode.appendChild(document.createTextNode("\u00a0" + arrElements[i]));
    anyone knows where can I get a list of of things like "\u00a0" ?

  • #10
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    oh, you have dig out again an old thread of mine. Yes, I have found out, the answer is on using unicode escapes:

    here's a chart:
    http://www.macchiato.com/unicode/chart/

    and here's an online convertor:
    http://people.w3.org/rishida/scripts/uniview/conversion
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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