wicherqm
wicherqm

Reputation: 245

jquery if all text is visible in div

Im trying to write plugin truncating text to only one line, and give user ability to expand text, i tested lots of them but i dont find suitable for me , to slow, problems if jquery is not loaded etc.

I done this in following way 1. initial span Very Long text w300 - means width 300

  1. $('.trunc').oneLine();

  2. plugin create > Very Long text [+]

css .trunc {overflow:hidden !important; white-space:nowrap !important; display:inline-block;}

  1. everything works ok So i have only one line + i can expand

PROBLEM i see expand sign[+] in every block, i want to see this only if text overflows block width I don't know how to determine if text is overflowing block. For example part of text is hidden.

Regards wicherqm

Upvotes: 2

Views: 1312

Answers (1)

Andy
Andy

Reputation: 30135

is this what you're looking for?
http://jsfiddle.net/jjTcL/

fiddle code:

$(function() {
    var $d = $('<div/>');
    $('div').wrapInner($d);
    alert($('div div')[0].scrollWidth);
});

Upvotes: 1

Related Questions