Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

length of text inside a span - and handle long text gracefully

Posted on 2013-01-24
3
Medium Priority
?
285 Views
Last Modified: 2013-01-30
How do I find the length of the text inside of a <span> tag?


I tried:

alert($('span[id*="lblDetails"]').length);

and it said "2" and I know that is not correct.


Essentially, what I want to do is if the text inside the span is greater than a certain length, I want to put "..." and then when they hover over the truncated text I want to show a popup  bubble of some sort that shows the full text.
0
Comment
Question by:Tom Knowlton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 1600 total points
ID: 38816098
alert($('span[id*="lblDetails"]').length); // display how mayn object jQUery found the provided selector : span[id*="lblDetails"]
If you get 2, that mean you've two objects...

To display the length if there's only ONE :
$('span[id*="lblDetails"]').text().length

Open in new window

To display the length if there's MORE THAN ONE (your current case) :
var total = 0;
$('span[id*="lblDetails"]').each(function() {
     var text = $(this).text();
     alert( "text is " + text );
     alert( "text length " + text.length );
     total = total + text.length;
     alert( "total is " + total );
})
alert( "last total is " + total )

Open in new window

0
 
LVL 22

Assisted Solution

by:Mrunal
Mrunal earned 400 total points
ID: 38818779
Another way is:

$('span[id*="lblDetails"]').html().length
0
 
LVL 5

Author Closing Comment

by:Tom Knowlton
ID: 38837545
Thank you.
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question