-2

I can you please tell me why my css is applied in my variable. when I write like this

 html+='<div>'+tenLengthString+'</div>';

fiddle: http://jsfiddle.net/yzaaJ/5/ it show my contend in row.but I need to show timestamp in all row.At every row I need to show timestamp.So I change my variable .

 html+='<div style=width:60%; float:left;><b>'+ hours + ":" + minutes + ":" +  seconds+'</b></div><div style=width:40%; float:left; text-align:right; ><b>'+ 1 +'&nbsp;&nbsp;&nbsp;&nbsp;</b></div></div><div>'+tenLengthString+'</div>';

fiddle http://jsfiddle.net/yzaaJ/6/

but it look different .how can i display timestamp in front of each row ?

var words = str.split(" ");
var tenLengthString = "";
var html='';
for(var index = 0; index < words.length; index++)
{
    var currentWord = words[index];
    var currentLength = tenLengthString.length;    
    if(((currentLength + currentWord.length + ((currentLength > 0) ? 1: 0))) > 30)
    {        
        html+='<div style=width:60%; float:left;><b>'+ hours + ":" + minutes + ":" +  seconds+'</b></div><div style=width:40%; float:left; text-align:right; ><b>'+ 1 +'&nbsp;&nbsp;&nbsp;&nbsp;</b></div></div><div>'+tenLengthString+'</div>';
        console.log(tenLengthString);        
        tenLengthString = currentWord;        
    } else {
        if(currentLength > 0)
            tenLengthString += " ";    
        tenLengthString += currentWord;
    }    
    if(index == words.length - 1){
      console.log(tenLengthString);
       html+='<div>'+tenLengthString+'</div>';

    }        
}
$("#test").html(html)

3 Answers3

0
  1. Enclose style in double quotes :style=""
  2. inner 'line-item level div's should be inline-block
  3. containing 'row level' div need opening tag
  4. lose the float styles
  5. Adjust styles to clean up the row.
  6. Consider using CSS to style the div's you are concatenating <div class="">
fnostro
  • 4,531
  • 1
  • 15
  • 23
0

You could simplify it a bit by separating the css. I also would prefer to create a list than so many divs.

html+='<li><span class="timestamp">'+ hours + ":" + minutes + 
   ":" +  seconds+'</span><span class="number">'+ 1 +
   '</span>'+tenLengthString+'</li>';

The css could be(for example):

li {
    list-style: none;
}

.timestamp {
    width:20%; 
    float: left;    
    font-weight: bold;
}

.number {
    float: left;
    text-align:left;
    width:20%;
    font-weight: bold;
}

And the jsfiddle

Raul Guiu
  • 2,374
  • 22
  • 37
0

I think you forgot the double quote on the style attributes.

 html+='<div style="width:60%; float:left;"><b>'+ hours + ":" + minutes + ":" +  seconds+'</b></div><div style="width:40%; float:left; text-align:right;" ><b>'+ 1 +'&nbsp;&nbsp;&nbsp;&nbsp;</b></div></div>

Sorry can't save on jsfiddle.