Reputation: 1197
I have got two jquery functions. When calling the first function classes are being removed and two onclick attributes are being changed.
But after calling the function to remove the classes the second function won't work, so the classes cannot be added anymore and the onclick event, too.
Edit 1: As already said the first function is working! The onclick events are being changed and the classes are being removed. It does not work when adding the same classes and functions again within the second function! When adding a new class it is working, but it is not working when adding one of the removed classes or onclick events!
Here's the code:
// show info
function showKursInfo() {
$(".kright").removeClass("kursMobileOpen");
$(".kleft").removeClass("kursMobileInfo");
$(".kright").attr("onclick","#");
$(".kheader").attr("onclick","hideKursInfo('someInfo');");
}
// hide info
function hideKursInfo() {
$(".kright").addClass("kursMobileOpen");
$(".kleft").addClass("kursMobileInfo");
$(".kright").attr("onclick","showKursInfo('someInfo');");
$(".kheader").attr("onclick","#");
}
Thanks for your help!
And to the ones who are disliking the question: Please tell me why this is a bad question?
Upvotes: 0
Views: 528
Reputation: 12452
Don't use attr
for register click events. Use click
or on
!
// show info
function showKursInfo() {
$(".kright").removeClass("kursMobileOpen");
$(".kleft").removeClass("kursMobileInfo");
$(".kright").off("click");
$(".kheader").on("click", hideKursInfo);
}
// hide info
function hideKursInfo() {
$(".kright").addClass("kursMobileOpen");
$(".kleft").addClass("kursMobileInfo");
$(".kright").on("click", showKursInfo);
$(".kheader").off("click");
}
Upvotes: 3