2

I am using jquery to make a slide down menu. The code works perfectly the first time the page loads. However, slideDown (the essential part of the click function) doesn't work more than once per menu item. Here is a js fiddle example http://jsfiddle.net/74ser/. Any help would be super appreciated.

$(document).ready(function() {
        $('.options').live('click',function() {
            console.log(this);
            var current = this.innerHTML;
            var list = listOfeverythingBut ("options", this);
            console.log(list);
            var stringA = new Array() ;
            var stringUl = new Array();
            for (var i =0; i < list.length; i++){
                var item ="."+list[i].innerHTML+"Menu";
                if ( $(item).length === 1){
                     stringA.push("ul"+ item ); 
                     stringUl.push(item + " a"); 
                }
            }
            stringA = stringA.toString();
            stringUl = stringUl.toString();
            console.log(stringA); 
            console.log(stringUl); 
            var currentItem = "." + current + "Menu";
            console.log(currentItem);
            if ( $(currentItem).length === 1){
                console.log("inOf"); 
                var toSlideDown = 'UL' + currentItem;
                console.log(toSlideDown); 
                console.log($(toSlideDown));
                $(toSlideDown).slideDown('medium');

            }
            else {
                $(".bottom").slideUp(20);
                $('.homeContent').delay(30).fadeIn(30);
            }           
            $(stringUl).slideUp('medium');
             moveDiv(this);
            $(stringA).removeClass('press');

            $('.options').removeClass('largeMenuStyle');
            $(this).addClass('largeMenuStyle');

            //setTimeout( function(){moveDiv(this)}, 2000); 
        });
});

note: the essential code is in the if ( $(currentItem).length === 1). I know that it enters the if because it console.logs 'inOf' each time I run the code. Even though it has the correct 'toSlideDown' variable it still doesn't work more than once.

I have already referred to these forum topics, but I haven't found my answer yet.

Jquery only works once per page load - want it work more than once without having to reload page

JQuery click event works only once

Community
  • 1
  • 1

2 Answers2

0

I'm sorry to say that but your code is very tricky and the HTML structure is very wrong.

Try my hot fix at: http://jsfiddle.net/jvLJs/1/

 $(toSlideDown + ' a').show();
 $(toSlideDown).hide().slideDown('medium');
phnkha
  • 7,782
  • 2
  • 24
  • 31
-1

I think this should help although is an old question. I've been having the same problem and I search everywhere to find a solution thinking my problem was in my jQuery file. Then I took a look on my css and found the problem.... basically jQuery animations DON'T WORK if you have declared transition in your css object. That's it or at least that's what fixed my problem.