I know there are a lot of similar posts, but I have not thus far been able to solve this.
context:
User selects a home,
homes have unique titles,
depending on title, resize font to prevent overflow
JS Fiddle: https://jsfiddle.net/9uvpun5o/3/
$(function() {
var that = $('#title'),
planName = that.html().length
;
// depending on html length, update font-size
if(planName > 30) {
that.css('font-size', '10px');
} else if(planName > 20) {
that.css('font-size', '12px');
} else if(planName > 10) {
that.css('font-size', '15px');
}
});
Font is sized according to html length, but I need this to be reactive. I tried creating an .on("change") event, but failed to implement correctly. Help?
Right now I'm just updating the title from console,
$('#title').html("big long description thing");
But, this will be done by selecting from a modal menu in the future.
EDIT
Ok, now I got it. Your JS should be this then:
The DOMSubtreeModified should fire whenever the content of the element changes (as this modifies the DOM Subtree). The 'click' part is not necessary, but I've kept it for testing purposes.
According to Dottoro, Opera doesn't support this event and IE 9 and below may not support or be buggy.
For more options and informations, check these other StackOverflow question:
By what you said, an user will "select a unit":
So, you need to change the font-size as part of this action. I used your code to make an example:
HTML
JS
Try to click in the list itens. You see? As a response to "changing the unit", the title and font-size changes.
If this answer doesn't help you, give more details.