The idea of functions in jQuery and what am I doing wrong?
Hi there!
I wrote a small script:
-
$(function() {
function klappmenu(id_name)
{
id_status=id_name+"_status";
head=id_name+"_head";
var id_status = $.cookie("+id_status+");
if (id_status == null){
$("h3#"+head).addClass('zu');
$("#"+id_name).css("display","none");
};
if (id_status == "zu"){
$("h3#"+head).removeClass('auf');
$("h3#"+head).addClass('zu');
$("#"+id_name).css("display","none");
};
if (id_status == "auf"){
$("h3#"+head).addClass('auf');
};
$("h3#"+head).click(function() {
if ($("h3#"+head).attr("class")=='auf'){
$(this).removeClass('auf');
$(this).addClass('zu');
$.cookie("+id_status+", "zu", { path: '/', expires: 100 });
$("#"+id_name).css("display","none");
} else{
$(this).removeClass('zu');
alert(head);
$(this).addClass('auf');
$.cookie("+id_status+", "auf", { path: '/', expires: 100 });
$("#"+id_name).slideDown(400);
}
});
}
klappmenu("last5");
klappmenu("cats");
klappmenu("komm");
klappmenu("roll");
klappmenu("hot");
klappmenu("year");
});
Why is this usage of functions not working? Only the last call of the function klappmenu is really functional. I think I missunderstand the usage of functions in generell here but can you help me to understand whats the problem?