I am trying the following code but it is not working. Logically it should be alright, but can anyone tell me what I am missing here ? The goal is, font size of (h1) tag should adjust automatically according to the height of its parent.
HTML
<div class="product-title">
<h1>Some Title which should not cross parent height and adjust font-size dynamically</h1>
</div>
CSS
.product-title{
height: 200px;
width: 200px;
}
JS
function adjustFontSize() {
$('#h1').each(function() {
var child = $(this);
var parent = child.parent();
child.css('font-size', '18'); //set max default font size
while (child.height() > parent.height() && parseInt(child.css('font-size')) > 9) { //check div height condition
child.css('font-size', (parseInt(child.css('font-size')) - 1) + "px"); //decrease font size accordingly
}
});
}