I have some javascript that is supposed to run after the window loads but for some reason, it never runs.
Here's my code:
function setClasses(){
document.getElementsByClassName("gchoice_35_0")[0].onclick = sedanShow;
document.getElementsByClassName("gchoice_22_0")[0].onclick = sedanShow;
document.getElementsByClassName("gchoice_34_0")[0].onclick = sedanShow;
document.getElementsByClassName("gchoice_34_1")[0].onclick = suvShow;
document.getElementsByClassName("gchoice_35_1")[0].onclick = suvShow;
document.getElementsByClassName("gchoice_22_1")[0].onclick = suvShow;
document.getElementsByClassName("gchoice_22_2")[0].onclick = vanShow;
document.getElementsByClassName("gchoice_35_2")[0].onclick = vanShow;
document.getElementsByClassName("gchoice_34_2")[0].onclick = vanShow;
}
window.onload = setClasses;
The setClasses() function doesn't seem to run. It does however work when I manually call it through the console of FireBug.
The code is placed in the header of my web page.
Any help is appreciated.
Full html snippet:
<head>
......
<script type="text/javascript">
function setClasses(){
document.getElementsByClassName("gchoice_35_0")[0].onclick = sedanShow;
document.getElementsByClassName("gchoice_22_0")[0].onclick = sedanShow;
document.getElementsByClassName("gchoice_34_0")[0].onclick = sedanShow;
document.getElementsByClassName("gchoice_34_1")[0].onclick = suvShow;
document.getElementsByClassName("gchoice_35_1")[0].onclick = suvShow;
document.getElementsByClassName("gchoice_22_1")[0].onclick = suvShow;
document.getElementsByClassName("gchoice_22_2")[0].onclick = vanShow;
document.getElementsByClassName("gchoice_35_2")[0].onclick = vanShow;
document.getElementsByClassName("gchoice_34_2")[0].onclick = vanShow;
}
function sedanShow(){
document.getElementById("sedan").style.display="inline"
document.getElementById("suv").style.display="none"
document.getElementById("van").style.display="none"
}
function suvShow(){
document.getElementById("sedan").style.display="none"
document.getElementById("suv").style.display="inline"
document.getElementById("van").style.display="none"
}
function vanShow(){
document.getElementById("sedan").style.display="none"
document.getElementById("suv").style.display="none"
document.getElementById("van").style.display="inline"
}
window.onload = setClasses;
</script>
......