I am trying to adapt this:
var h2=$('.block h2');
var divh=$('.block').height();
while ($(h2).outerHeight()>divh) {
alert('enters while');
$(h2).text(function (index, text) {
return text.replace(/\W*\s(\S)*$/, '...');
});
}
as explained here: Cross browsers mult-lines text overflow with ellipsis appended within a width&height fixed div?
The problem I have encountered in my case is that I have various li
where each one contains a .block
which has a h2
tag per li
Example:
<li>
<div class="block">
....
<h2>Tittleasfasjgpashgj9ahgpasgnapsighapighapsogna</h2>
...
</div>
</li>
<li>
<div class="block">
....
<h2>5Tittleasfasjgpashgj9ahgpasgnapsighapighapsogna</h2>
...
https://i.stack.imgur.com/lI82f.jpg
Having .block
set with 200px, inside having img
set to height: 90px;
and a padding: 5px
now I need to take the height left beneath img and compare to h2
's height.
But it doesn't work either, it just doesn't do the if, but divh
contains data (200, the 200px set in css).
Edit:
So I just figure out that the best way to fix this is to set a height to h2
tag and than compare its content height with the set one.