Reputation: 8400
I have div with fixed width of 30%. I want to get the length of text in that div.
Here is my fiddle
What i am doing here is ,
var text=$('#test').text();
text=text.trim();
var len=text.length;
alert(text);
alert(len);
I am getting length of only text . How can i get length of text after applying html tags to it.
Current behaviour : Getting length as 105.
Expected behaviour : 29 * total line [ 29 is atmost characters can be in line of div ]
Update
I also want to to count the length including the area (green) shown in following image.
Upvotes: 2
Views: 11677
Reputation: 6411
http://jsfiddle.net/aamir/4M8V7/7/
//With html length
console.log( $.trim($('#test').html()).length );
//Without html length
console.log( $.trim($('#test').text()).length );
Upvotes: 3