0

I am having a terrible time with the first of the following scripts. I'm not sure if the issue is that there are two similar scripts on the page or if my HTML5 code is incorrect. Any help would be appreciated:

 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
 <script>
 $('.btn').click(function(){
 $('.btn').removeClass('active');
 $(this).addClass('active');
 });
 </script>

 <script type="text/javascript">
 function MM_showHideLayers() { //v9.0
 var i,p,v,obj,args=MM_showHideLayers.arguments;
 for (i=0; i<(args.length-2); i+=3) 
 with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
 if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
 obj.visibility=v; }
 }
 </script>

 </head>

And the targeted HTML:

 <div class=links>
 <ul>
 <li>
 <a href="#"   onclick="MM_showHideLayers('what_we_do','','show');MM_showHideLayers('our_mission','','hide');MM_showHideLayers('who_we_are','','hide')" class="active btn" >WHAT WE DO</a> | 
 </li>
 <li>
 <a href="#" onclick="MM_showHideLayers('who_we_are','','hide');MM_showHideLayers('our_mission','','show');MM_showHideLayers('what_we_do','','hide')" class="btn" >OUR MISSION</a> | 
 </li>
 <li>
 <a href="#" onclick="MM_showHideLayers('our_mission','','hide');MM_showHideLayers('who_we_are','','show');MM_showHideLayers('what_we_do','','hide')" class="btn" >WHO WE ARE</a>

 </li>
 </ul>
 </div>

As stated, the problem is in the first script where my intention is that the active anchor should change back to the default anchor attribute as the others are clicked by the user.

Thanks again.

0

1 Answer 1

1

Wrap all into document.ready()

<script>
$(document).ready(function(){
     $('.btn').click(function(){
     $('.btn').removeClass('active');
     $(this).addClass('active');
     });
}):
</script>
Sign up to request clarification or add additional context in comments.

5 Comments

or you could use $(fn);
Thanks, it still was not working so I also changed the link to: <script src="ajax.googleapis.com/ajax/libs/jquery/1.5.2/…> and its all good now.
Ok, try always to uses the lastest jQuery version. If the plugin does not work is much better search another.
Well v1.11.1 should be the latest -no? But v1.5.2 seems to load faster and as stated works with this particular script. The 1.11.1 was spinning the page out and not working at all with the script.
Yeas, maybe the plugin does not support the lastest version :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.