I am wondering if there is any way with Javascript to get a text when it's out of its own <div>. For example if a text is made of 3 sentences, and the last one is only halfy displayed, is there a way to get the entire last sentence, or the first word that isn't displayed with JavaScript ?
Example :
HTML
<div>loooooong loooooong text. Second sentence. Third sentence</div>
CSS
div {
max-width: 60px;
max-height: 50px;
overflow: hidden;
text-overflow: ellipsis;
}
To get all the text:
var node = document.getElementsByClass('div')[0];
var fulltext = node.textContent; // gets all textual content, hidden or not
To get the text displayed:
var vistext = node.innerText; // gets only text displayed on page (despite my comment!)
Hidden text is then fulltext - vistext
var hiddentext = fulltext.substr(vistext.length);
Should do the trick...
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