Using jQuery, you can do something like this:
$(function(){ $('#smallT').click(setTextToSmall); $('#mediumT').click(setTextToMedium); $('#largeT').click(setTextToLarge); }); function setTextToSmall(evt) { $('.text-to-resize').addClass('small').removeClass('medium').removeClass('large'); }
To clarify this, CSS is actually used for resizing. You will have three CSS classes named "small", "medium" and "large":
.small { font-size: 0.5em; } .medium { font-size: 1em; } .large { font-size: 1.5em; }
The setTextToSmall() function is called when the user clicks on the small "T". It adds a small class to all elements that already have a text-to-resize class, and removes the middle and large classes. So, if you have it until you click:
<div class="text-to-resize">Some sample text</div>
You will have this after clicking:
<div class="text-to-resize small">Some sample text</div>
If you want to apply this to every element of the page, you simply change setTextToSmall() to the following:
function setTextToSmall(evt) { $().addClass('small').removeClass('medium').removeClass('large'); }
The advantage of jQuery (or other frameworks for that matter) is that it abstracts the DOM, which is very complex in different browsers. For example, in direct Javascript, you can instinctively use document.getElementsByClassName() . However, this method does not exist in any version of IE .
source share