So I wanted to know how to check if a text of a div (child) in another div (parent) is overflowing (hidden). If it's true another div should be added at the bottom inside of the parent and style changes should be applied to the child.
I already found a JavaScript function to check the overflow in this question but since I am a complete beginner in JS I need some help to connect the specific tasks. Maybe screw up with the function, too. Please take a look at it =) I hope someone is willing to help me.
I tried to "form" the tasks with JQuery but I dont' know if they work like this:
$('.child').css({"margin":"+=10px";});
With this one I want to add 10px to the current margin.
$('.parent').append('<div class="child_2"></div}');
With this I want to add a div class at the bottom inside the parent.
HTML:
<div class="parent">
<div class="child">Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum
</div>
</div>
CSS
.parent{
width:150px;
height: 100px;
float:left;
background-color: red;
}
.child {
max-height: 80px;
margin:10px;
background: green;
overflow: hidden;
}
Javascript
function checkOverflow(child)
{
var curOverflow = child.style.overflow;
if ( !curOverflow || curOverflow === "hidden" )child.style.overflow = "visible";
var isOverflowing = child.clientWidth < child.scrollWidth || child.clientHeight < child.scrollHeight;
child.style.overflow = curOverflow;
return isOverflowing;
}