开发者

onClick not working on an 'a' element

开发者 https://www.devze.com 2023-03-23 06:10 出处:网络
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:

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"

0

精彩评论

暂无评论...
验证码 换一张
取 消