The problem arises from the first few lines.
$('#registrieren').attr('id', 'menuAktiv'); menu='registrieren'; $('#registrieren').click(function() { if(menu != 'registrieren') { $('#menuAktiv').attr('id', menu); $('#registrieren').attr('id', 'menuAktiv'); menu='registrieren'; } alert(menu); });
The third line of $ ('# registrieren') does not indicate anything. $ ('# registrieren') searches for the dom element with the id = "registrieren" element. Well, since you changed this element identifier to something else, $ ('# registrieren') will not give you anything.
To make it work (not necessarily the best approach to what your code does), and to prove that what I just described, in fact, what you can do is save the link to this element in a variable (preliminary replacement). Then in the future you will use this anytime you want to target an item.
var registrieren = $('#registrieren'); registrieren.attr('id', 'menuAktiv'); registrieren.click(function() {
Regarding the use of classes instead of ids for โstate changesโ, yes, this is probably a much better idea - no need to keep references to previous identifiers.
source share