I made a list with <option> items and whenever I try to verify which one has been selected using a script the console in Chrome says:
Uncaught TypeError: Cannot read property 'value' of null
I don't see what's wrong in my code in both HTML and JS everything seems normally?
Here's the HTML:
<select name="part" id="optionFonts">
<option value="default">--- Choose what you want the changes to affect --- </option>
<option value="all"> ALL ELEMENTS </option>
<option value="title-and-headings"> TITLES AND HEADINGS </option>
<option value="headings"> ALL HEADINGS </option>
<option value="allpars"> ALL PARAGRAPHS </option>
<option value="title"> TITLE </option>
<option value="heading1"> FIRST HEADING </option>
<option value="par1"> FIRST PARAGRAPH </option>
<option value="par2"> SECOND PARAGRAPH </option>
<option value="par3"> THIRD PARAGRAPH </option>
<option value="par4"> FOURTH PARAGRAPH </option>
<option value="heading2"> SECOND HEADING </option>
<option value="par5"> FIFTH PARAGRAPH </option>
</select>
And in the JS
var optionFonts = document.getElementById('optionFonts');
var title = document.getElementById('stitle');
var div1Title = document.getElementById('d1Title');
var div1Par = document.getElementById('d1Par');
var p1 = document.getElementById('p1');
var p2 = document.getElementById('p2');
var p3 = document.getElementById('p3');
var d2Title = document.getElementById('d2Title');
var d2Par = document.getElementById('d2Par');
function changeTextFontToBebas() {
switch(optionFonts.value) {
case 'all':
title.style.fontFamily = "Bebas";
div1Title.style.fontFamily = "Bebas";
div1Par.style.fontFamily = "Bebas";
p1.style.fontFamily = "Bebas";
p2.style.fontFamily = "Bebas";
p3.style.fontFamily = "Bebas";
d2Title.style.fontFamily = "Bebas";
d2Par.style.fontFamily = "Bebas";
break;
}
}
It should change the font of everything when I press the box about that font (in this case the Bebas font) and when I press it it will run the function changeTextFontToBebas() function which will also verify what's been checked first, but it just gives that error instead.
Thanks in advance