I have a DIV with a multi-line paragraph.
Is there any way (maybe using jQuery) to only show the first line of the paragraph and hide the others?
I have a DIV with a multi-line paragraph.
Is there any way (maybe using jQuery) to only show the first line of the paragraph and hide the others?
There is not an outright way to do this by specifying the first line.I would suggest changing the height of the DIV using CSS to only show the first line. It would seem to me to be the simplest solution. If you then want to change to show the whole line with javascript just use it to change the height of the DIV back to 100%.EDIT: I stand corrected, I was not aware that there was a first-line pseudo class. However changing the height may still be the simplest way.
No need for JavaScript, measuring height, or changing visibility. Just set the paragraph to display inline and not to wrap its text. You'll want to set the overflow on the parent div to "hidden" so the remaining lines in the paragraph don't spill out.
http://jsfiddle.net/VvdBs/
It has been awhile since this was answered but seeing there is no example here is one that works pretty well:
http://jsfiddle.net/h82313am/
Just adding this here as an idea. It allows you to show and hide the text with a text box. CSS only.
Determine the height of your line and set the height of the div such that only one line is shown, and set the div's
overflow
attribute tohidden
.I haven't tried it, but you should be able to do a little better using visibility, e.g.
and then setting up a style