I have two separate classes in css, and I want the links to switch from one to the other when clicked. I dont even get the alert, so I think there is a problem with the onClick
part:
<script type="text/javascript">
function find(word) {开发者_JS百科
alert('check');
if (document.getElementById(word).className == "remaining";) {
document.getElementById(word).className = "found";
} else {
document.getElementById(word).className = "remaining";
};
};
</script>
[...]
<a href="#" id="word20" class="remaining" onClick="find('word20');">LOL</a>
Thanks in advance
if (document.getElementById(word).className == "remaining";) {
------------------------- E R R O R ----------------------^
The spurious semicolon here is the error.
I found the error in Firefox JavaScript's Error Console. It is easy to launch it using Ctrl+Shift+J.
You have a sintax error, the script should be like this:
<script type="text/javascript">
function find(word) {
alert('check');
if (document.getElementById(word).className == "remaining") {
document.getElementById(word).className = "found";
} else {
document.getElementById(word).className = "remaining";
};
};
Remove the ; next to "remaining"
精彩评论