Question:
How can I resize a particular div on an HTML page using JavaScript?
Cifru
2010-05-22 18:18:06 UTC
I have a particular script which I posted below. When I change the size of the font... all the fonts change. I would like to change the font size using the JavaScript below of a particular div only. My div name in my case is "contentwide". What should I do to the code below to effect the font size of this particular div? Thank you.

/*------------------------------------------------------------
Document Text Sizer- Copyright 2003 - Taewook Kang. All rights reserved.
Coded by: Taewook Kang (txkang.REMOVETHIS@hotmail.com)
Web Site: http://txkang.com
Script featured on Dynamic Drive (http://www.dynamicdrive.com)

Please retain this copyright notice in the script.
License is granted to user to reuse this code on
their own website if, and only if,
this entire copyright notice is included.
--------------------------------------------------------------*/

//Specify affected tags. Add or remove from list:
var tgs = new Array( 'div','td','tr');

//Specify spectrum of different font sizes:
var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );
var startSz = 2;

function ts( trgt,inc ) {
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[ sz ];

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 ];
}
}
Three answers:
bo75007
2010-05-22 18:45:06 UTC
This script is not for changing individual divs its designed to change all of whichever tag is selected (div td and tr by default)





If you only have one div that you want to change the font size on than you would be far better off giving that particular div its own style with simple html/css code like so:



hello world




Just make sure that your script/function above executes beforehand so that it doesn't overwrite what you are changing. In other words, make it show up in your code below the point where it says: ts(blah, blah); Or just remove the script all together if you are only changing font size on individual divs.
?
2016-10-25 08:58:06 UTC
As others have suggested, you're in a position to no longer earnings administration of the close administration of the window itself. For administration of cover/show or greying of a particular button, you're likely perfect going with Ajax to dynamically guard the button homes as needed.
2010-05-22 18:25:30 UTC
Change the innerHTML of the div to what it is plus style with a font or text change.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...