Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
59
rated 0 times [  63] [ 4]  / answers: 1 / hits: 64923  / 11 Years ago, fri, january 17, 2014, 12:00:00

I'm using a javascript snippet in order for visitors to my site to increase the font size on all paragraphs using the following javascript:



function increaseFontSize() {  

var paragraphs = document.getElementsByTagName('p');

for(i=0;i<paragraphs.length;i++) {

if(paragraphs[i].style.fontSize) {
var s = parseInt(paragraphs[i].style.fontSize.replace(px,));
} else {
var s = 14;
}

if(s != max) {
s += 1;
}
paragraphs[i].style.fontSize = s+px
}
}


How can I also include li to this code so that p and li are the selected elements that are affected?



I would also like to avoid adding a class or an id to my li or ul. Is there a way to select two tags at once?


More From » html

 Answers
21

No, you can't select multiple tags with a single call to getElementsByTagName. You can either do two queries using getElementsByTagName or use querySelectorAll.



JSFiddle



var elems = document.querySelectorAll('p,li')

[#73095] Thursday, January 16, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
quinn

Total Points: 160
Total Questions: 86
Total Answers: 101

Location: Belarus
Member since Tue, Mar 14, 2023
1 Year ago
;