0

Im new to Javascript and jquery and I almost have my problem solved. I built an accordion menu that in some versions of IE is bad, I mean, Im sure its bad overall, but it stops all Javascript on the page from working if its called first. Im guessing its some syntax thing I dont know and therefore cant find.

// JavaScript Document

function initiateMenu() {
var pathname = window.location;
console.log( window.location.pathname );

$('.sub').hide();
$("#menu a[href='"+pathname+"']").next().show();
$("#menu a[href='"+pathname+"']").parents('.sub').show();
$("ul.sub").parent().prepend("<span></span>");

$('#menu li span').click(
  function() {
    var checkElement = $(this).parent().find("ul.sub");

    if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
      return false;
      }

    if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
      $('#menu ul:visible').slideUp('normal');
      checkElement.slideDown('normal');
      return false;
      }
    }
  );
}

$(document).ready(function() {initiateMenu();});

I cant see what is wrong with the script but its stopping all other Javascript from working.

If i call it after other scripts on the page the other scripts work. Please help If you need to look at the page its http://www.jardencustom.com/2012/

The home page has the accordion script moved below the other scripts, the rest do not.

Emre Erkan
  • 8,433
  • 3
  • 48
  • 53
Scotosaurus
  • 353
  • 3
  • 18
  • I just opened the site and there are no errors on the page, according to Firebug. – ClarkeyBoy Dec 07 '11 at 21:16
  • 1
    Hi, I'm not able to reproduce the errors you mention in IE8 or IE7. Can you be more specific in what version of IE you experience those problems. Also can you check ou Developer Tools if it indicates an error (open it by pressing F12 in IE8 or higher). And please do me a favor, please please please don't refer to JavaScript as java... – PM5544 Dec 07 '11 at 21:19
  • 1
    Java is to Javascript as Car is to Carpet (the only similarity is the name) – hugomg Dec 07 '11 at 21:48
  • You can access developer tools with F12, then at script tab start debugging and try to find the problem. – Emre Erkan Dec 07 '11 at 22:56

1 Answers1

2

get rid of this:

console.log( window.location.pathname );

IE doesn't support console and will break if you use it.

check out this SO question and answer: What happened to console.log in IE8?

Community
  • 1
  • 1
Kai Qing
  • 18,793
  • 5
  • 39
  • 57