...

View Full Version : space on text node DOM2



sudhakar_jr
12-03-2005, 06:36 AM
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 ???

Kor
12-05-2005, 12:21 PM
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)

sudhakar_jr
12-05-2005, 02:39 PM
thanx

Kor
12-05-2005, 02:48 PM
Maybe something like this? (it depends on your needs)


<!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;
position: relative;
left: 10px;
}
-->
</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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum