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