I'm trying to show/hide content in the following doctype:
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
Here's my javascript:
<script type="text/javascript"> function question(clicked) {
var q = document.getElementsByTagName("div");
for(var x=0; x<q.length; x++) {
title = q[x].getAttribute("title");
if (title == 'q') {
if (q[x].id == clicked) {
if (q[x].style.display == 'block') {
q[x].style.display = 'none';
}
else {
q[x].style.display = 'block';
}
}else {
q[x].style.display = 'none';
}
}
} } </script>
On Validation, it returns these errors: 1. Error Line 9, Column 30: character ";" not allowed in attribute specification list
for(var x=0; x<q.length; x++) {
Error Line 9, Column 30: element "q.length" undefined
for(var x=0; x<q.length; x++) {Error Line 25, Column 9: end tag for "q.length" omitted, but OMITTAG NO was specified
Info Line 9, Column 21: start tag was here
for(var x=0; x<q.length; x++) {
I'm learning Javascript now, and have tried to Google & fix this about 3 dozen ways by now. Can anyone help me? If I need to try a different script to show/hide, at this point, I'd scrap what I have and do it.
Thanks in advance!
<script>block? It feels to me that it's trying to interpret your JavaScript as XHTML: "end tag for q.length omitted" is a strange one. The JavaScript itself seems perfectly valid.