increasing font size

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

increasing font size

Post 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?
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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.
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Post 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.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Re: increasing font size

Post 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.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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];
	}
}
darryladie
Forum Commoner
Posts: 62
Joined: Thu Mar 02, 2006 6:14 pm
Location: East Sussex, UK

Post 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.
Post Reply