Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getElementsByTagName for two tags at once

Tags:

javascript

I use this:

function setFontSize() {
   var p = document.getElementsByTagName('td');
   for(i=0;i<p.length;i++) {
      p[i].style.fontSize = selectedsize+"px"
   }
}

What's the simplest and best way to throw in 'th' too?

like image 787
Ole Sørensen Avatar asked May 26 '13 12:05

Ole Sørensen


1 Answers

If you don't have to support older browsers you can use document.querySelectorAll(..).

function setFontSize() {
   var i;
   var p = document.querySelectorAll('td, tr');
   for( i = 0; i < p.length; i++ ) {
      p[i].style.fontSize = selectedsize + "px"
   }
}
like image 95
gregor Avatar answered Oct 06 '22 19:10

gregor