Page 1 of 1

increasing font size

Posted: Tue Feb 28, 2006 8:05 am
by shiznatix
Hey again, another JS problem.

I need a way to increase the font size of some text on the fly. I can not use font tags. How do I do this?

Posted: Tue Feb 28, 2006 8:31 am
by CoderGoblin
Only ways I know of... If the text is all in one element you can set the element class to be something else defined by CSS to be larger. If not (and you state you cannot use the font element) make it a span with a css style. If the font style is to change (onmouseout etc) you would then potentially have to remove the span (moving the contents out) when the mouse moves out.

Posted: Tue Feb 28, 2006 9:46 am
by matthijs
You could do it or see how it's done in many of the available stylesheet switchers. I have used them a couple of times.

Re: increasing font size

Posted: Tue Feb 28, 2006 6:23 pm
by Roja
shiznatix wrote:Hey again, another JS problem.

I need a way to increase the font size of some text on the fly. I can not use font tags. How do I do this?
Put selectors (id's or classes) on the elements containing the text you need to increase the font size for.

Then use css to change the font size on those elements.

Posted: Wed Mar 01, 2006 1:40 am
by shiznatix
thanks for the input. I found this realy handy script online:

Code: Select all

//font sizes
var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );
//default size (small)
var startSz = 2;

function ts(trgt, inc)
{
	//if you can't get elements, just quit the function
	if (!document.getElementById)
		return
	
	var d = document, cEl = null, sz = startSz, i, j, cTags;
	
	sz += inc;

	if ( sz < 0 )
		sz = 0;
	if ( sz > 6 )
		sz = 6;
	
	startSz = sz;
		
	if (!(cEl = d.getElementById(trgt)))
		cEl = d.getElementsByTagName(trgt)[0];

	cEl.style.fontSize = szs[ z];

	for (i = 0 ; i < tgs.length ; i++)
	{
		cTags = cEl.getElementsByTagName(tgs[i]);

		for (j = 0; j < cTags.length; j++)
			cTags[j].style.fontSize = szs[sz];
	}
}

Posted: Fri Mar 03, 2006 7:52 am
by darryladie
Why scrap that and try this:

http://www.dyn-web.com/dhtml/sizefont/index.php

I have used it in the past it's pretty good if you're using CSS.