Jayden Bell
Jayden Bell

Reputation: 1

JavaScript showing error

I have an accordion menu and a lightwindow script on my web page. The lightwindow script does not work because of the accordion script because if I delete the latter the lightwindow script works. There must be a conflict but what? Here is the head section of my page:

<script type="text/javascript" src="lightwindow/javascript/prototype.js"></script>
<script type="text/javascript" src="lightwindow/javascript/scriptaculous.js?load=effects"></script>
<script type="text/javascript" src="lightwindow/javascript/lightwindow.js"></script>
<link rel="stylesheet" href="lightwindow/css/lightwindow.css" type="text/css" media="screen" />
<!-- accordion scripts -->
<script src="js/jquery-1.2.1.min.js" type="text/javascript"></script>
<script src="js/menu.js" type="text/javascript"></script>
<script src="js/jquery.cookie.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="css/accordion.css" />

Upvotes: 0

Views: 97

Answers (2)

Praveen Kumar Purushothaman
Praveen Kumar Purushothaman

Reputation: 167212

You are loading both prototype.js and jquery.js.

Use jQuery using noConflict.

$.noConflict();

And replace all the instances of $ for jQuery with jQuery.

Upvotes: 0

y_nk
y_nk

Reputation: 2275

This shit happens when using too much libraries and plugins...

Try use the noConflict function of jQuery so you can use prototype and scriptaculous with it. The documentation says :

<script type="text/javascript" src="other_lib.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
  $.noConflict();
  jQuery(document).ready(function($) {
    // Code that uses jQuery's $ can follow here.
  });
  // Code that uses other library's $ can follow here.
</script>

But honestly, if i were you, i would choose ONE library i would use for my website, find plugins that do the same since it's damn full of plugins out there.

Also, update jQuery call to something like :

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>jQuery || document.write('<script src="js/jquery.min.js"><\/script>')

Upvotes: 0

Related Questions