Unexpected token ILLEGAL with jQuery
Posted
by
Bram Vanroy
on Stack Overflow
See other posts from Stack Overflow
or by Bram Vanroy
Published on 2012-02-23T13:19:33Z
Indexed on
2012/06/30
9:16 UTC
Read the original article
Hit count: 178
JavaScript
|autofill
So, I have a website with an autoFontSize script (Got it from stackoverflow, but slightly edited it too loop over each div with that specific class)
(function ($) {
$.fn.textfill = function (options) {
this.each(function () {
var fontSize = options.maxFontPixels;
var ourText = $('h2 a', this);
var maxHeight = $(this).height();
var maxWidth = $(this).width();
var textHeight;
var textWidth;
do {
ourText.css('font-size', fontSize);
textHeight = ourText.height();
textWidth = ourText.width();
fontSize = fontSize - 1;
} while ((textHeight > maxHeight || textWidth > maxWidth) && fontSize > 16);
});
return this;
};
})(jQuery);
$(document).ready(function () {
$('.fotonode.fotopagina').textfill({
maxFontPixels: 30
});
});?
And a (simplified) HTML structure:
<div class="fotonode fotopagina">
<h2><a href="#">Testing Title</a></h2>
</div>
For some reason this doesn't work (neither locally nor live) BUT it does work on JSfiddle: http://jsfiddle.net/Yb9yj/
I read somewhere that this can cause problems. I copied the code from jsfiddle to my file, so maybe I have (unintentionally) copied some white spaces that shouldn't be there or something. I don't know. But how can I solve this then?
© Stack Overflow or respective owner