Aaron Brewer
Aaron Brewer

Reputation: 3677

Conflicting jQuery/JavaScript?

I am trying to run two different jQuery/Java Scripts under one file name... And when I do they do not seem to work hand-in-hand one works and the other doesn't.

I have a page that requires both the scripts, so I tried putting those two in one file. That doesn't work, but when I split them up, they seem to work...

I know very little about JavaScript and jQuery can someone guide me into allowing these two scripts not to conflict?

$(document).ready(function($) {
$(".myslider").slideshow({
  width      : 643,
  height     : 303,
  control    : false,
  transition : 'squarerandom',
});
$(document).ready(function() {
    $('.navigation .submenu > li').bind('mouseover', openSubMenu);
    $('.navigation .submenu > li').bind('mouseout', closeSubMenu);
    function openSubMenu() {
        $(this).find('ul').css('visibility', 'visible');    
    };
    function closeSubMenu() {
        $(this).find('ul').css('visibility', 'hidden'); 
    };         
});

I bet you can guess the two scripts. Thanks! Aaron

Upvotes: 0

Views: 139

Answers (2)

SLaks
SLaks

Reputation: 888283

You have a syntax error: transition : 'squarerandom', shouldn't have a trailing comma.

That makes the entire file invalid.

Upvotes: 2

James Montagne
James Montagne

Reputation: 78770

Your syntax is off. Try this:

$(document).ready(function() {
    $(".myslider").slideshow({
      width      : 643,
      height     : 303,
      control    : false,
     transition : 'squarerandom',
   });

    $('.navigation .submenu > li').bind('mouseover', openSubMenu);
    $('.navigation .submenu > li').bind('mouseout', closeSubMenu);
    function openSubMenu() {
        $(this).find('ul').css('visibility', 'visible');    
    };
    function closeSubMenu() {
        $(this).find('ul').css('visibility', 'hidden'); 
    };         
});

No need for 2 different document.readys, plus you weren't closing one of them.

Upvotes: 4

Related Questions