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 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    space on text node DOM2

    Hi


    var lbl=document.createElement('LABEL');
    var txt=document.createTextNode('text');
    lbl.appendChild(txt);


    in above txt node i want a space infront of that


    i tried below, but no use


    var txt=document.createTextNode(' text');


    any idea ???

  • #2
    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
    Normally you might have used unicode '\u0020' to insert a space, but I guess that in this case you could better use CSS to position your text inside your element, or inside a span (or div)
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New Coder
    Join Date
    Oct 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanx

  • #4
    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
    Maybe something like this? (it depends on your needs)
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
    <
    html>
    <
    head>
    <
    title>Untitled Document</title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <
    meta http-equiv="Content-Style-Type" content="text/css">
    <
    meta http-equiv="Content-Script-Type" content="text/javascript">
    <
    style type="text/css">
    <!--
    .
    lblcss {
        
    background-color#ccffff;
        
    positionrelative;
        
    left10px;
    }
    -->
    </
    style>
    <
    script type="text/javascript">
    onload=function(){
    var 
    root document.getElementById('mydiv');
    var 
    lbl=document.createElement('label');
    lbl.className='lblcss'
    var txt document.createTextNode('text')
    lbl.appendChild(txt)
    root.appendChild(lbl)
    }
    </script>
    </head>
    <body>
    <div id='mydiv' style="background:#cccccc"></div>
    </body>
    </html> 
    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
    •