Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

font-size changes for body except not inside table 1

Status
Not open for further replies.

shaunacg

Programmer
Aug 1, 2003
71
GB
Hi,

I have a button that when pressed executes the following:

document.body.style.fontSize="16px";

so everything changes to 16px except for what is inside my table. How can I get this to change?

I've tried things like:
document.td.style.fontSize="16px";

no use. Any ideas?

Thanks

s
 
try this

document.getElementByTagName("td").style.fontSize="16px";

HTH

Simon
 
There might be a much easier way to do this, but this might get you started. By the way, what's up with the code tags picking up italics? I had to change my i's to j's in the for loop cause it was getting italicized.
Code:
<html>
<head>
<script language=JavaScript>
function changeSize() {
   var fontText = document.getElementsByTagName(&quot;font&quot;);
   for (j = 0; j < fontText.length; j++) {
      fontText[j].style.fontSize=&quot;24px&quot;;
   }
}
</script>
</head>
<body>
<form name=blahForm>
<font>
blah1<br>
blah2<br>
</font>
<table name=blahTable border=1>
<tr>
<td><font>cell (1, 1)</font></td>
<td><font>cell (2, 1)</font></td>
</tr>
<tr>
<td><font>cell (1, 2)</font></td>
<td><font>cell (2, 2)</font></td>
</tr>
<input type=button value='Click me' onclick='changeSize()'>
</form>
</body>
</html>

-kaht

banghead.gif
 
Guess simon and I are sort of on the same wavelength. I wasn't sure if td's supported the fontSize attribute and that's why shaunacg was runnin into problems or not. Anyway, you can implement my code and change it to td in the function if you wanna wipe out all the font tags.

-kaht

banghead.gif
 
Hi Simon and Kaht,

Thanks for your help. The document.getElementByTagName(&quot;td&quot;) brought up an error that said Object does not support property or method. But you would think it should work. Then I tried Kaht's method and then again without the font tags but the tds. Works perfectly. Thank-you!

S
 

this should work

document.getElementByTagName(&quot;td&quot;).style.font-size=&quot;16px&quot;;
 
The document.getElementsByTagName(&quot;TD&quot;) returns an array of tags, not a single property...so you can't use the style attribute on that alone...you have to loop through all the TD tags:


Code:
[ignore]
function changeSize() {
  var arrTDTags = document.getElementsByTagName(&quot;td&quot;);

  for(i=0;i<arrTDTags.length;i++) {
    arrTDTags[ i ].style.fontSize		= &quot;20px&quot;;
  }
}[/ignore]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top