I have the following situation.
<ul>
<li><span> text </span></li>
</ul>
I use the following jquery to get the text content and width…
$("ul li").each(function()
{
var textIndex = $(this).index();
var $text = $(this).find("span").text() // this works..
var textWidth = $text.width(); // this does not work..
});
How do I get the text Width along with getting its index, and text data?
A few things:
indexandvalue. Then you can get the index of theliwithout the extra jQuery call..text()call returns the text as a string, strings do not have a.width()method on them.span, not the text.Try this: