Example: a div with width of 30px with the words "this is text". Let's say that, since the width is narrow, it renders on the page like this:
this
is
text
(3 lines). Is there a way in jQuery to tell how many lines it takes to render to the page? For example, something like, $("#container").lineCount()
.
Business purpose: if my content exceeds a certain number of lines, I want to manipulate it so that a scroll bar does not appear, but I also have a fixed height, so I don't want to mess with overflow css prop.
Thanks!
To check in for your flight: Visit your airline's website as soon as 24-hours prior to the departure of your first flight. Use the confirmation number in your online account to check in. You will also be able to view your seats and, if permitted by the airlines, confirm your seating preferences.
Most airline website will have a 'Web Check In' or 'Check In' tab on their main website. If you can't see it, find your account/booking details page, where you will find an option to web check in.
In most cases, you will only need to go to check-in when you have checked-in online if you need to drop off an item of hold baggage. Please ensure that you are aware of the hand baggage requirements for your specific airline before you travel.
This is tricky but can be done, even if there is no specified line-height or other style. It does involve a bunch of moving parts.
First, build a "sacrificial" container <div>
. Fill it with a known number of lines of text, one character each, and position it far off-screen:
// calculate height per line
$calcdiv = $('<div/>').css({
width: '50px',
position: 'absolute', // don't affect layout
left: '-2000px' // position far off=screen
}).html('A<br />B<br />C<br />D<br />E'); // add five lines
$('body').append( $calcdiv ); // make the browser render it
var lineHeight = $calcdiv.height()/5; // average height per line
Now we know the approximate height of a line, in pixels, as rendered by this browser. We turn our attention to the box to be measured:
$origDiv = $('div#div_to_measure');
$measureDiv = $origDiv.clone(); // clone it
$measureDiv.css({
position: 'absolute',
left: '-1000px', // position far off-screen
height: 'auto' // let it grow to its natural full height
});
$('body').append( $measurediv ); // add it to the DOM, browser will render it
...and now we know the approximate number of lines in the box if allowed to attain its natural dimensions as rendered by the browser:
var numLines = $measureDiv.height() / lineHeight;
We have to clone()
because the original box to be measured may have its height restricted by the current page styles and layout.
Now some cleanup:
$calcdiv.remove();
$measureDiv.remove();
Here's an example: http://jsfiddle.net/redler/FuWue/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With