kirill578 Posted February 17, 2011 Share Posted February 17, 2011 Is it possible to disable jQuery event by click link or something for example //some event $('div#somediv').hover( $('body').css("background","#b7d921"); ); $('body').click( <!-- some function that will disable the first event that switchs color --> ); Quote Link to comment https://forums.phpfreaks.com/topic/228010-jquery-disable-event/ Share on other sites More sharing options...
Maq Posted February 17, 2011 Share Posted February 17, 2011 In the future, please use tags. Quote Link to comment https://forums.phpfreaks.com/topic/228010-jquery-disable-event/#findComment-1175766 Share on other sites More sharing options...
Maq Posted February 17, 2011 Share Posted February 17, 2011 Have a look at - .unbind. Quote Link to comment https://forums.phpfreaks.com/topic/228010-jquery-disable-event/#findComment-1175769 Share on other sites More sharing options...
kirill578 Posted February 17, 2011 Author Share Posted February 17, 2011 It's kind of complected.Isn't there a way to disable a whole function like this: function somefunction() { <!-- lots of event --> }; $(a#somelink).click( <!-- disable somefunction --> ); Quote Link to comment https://forums.phpfreaks.com/topic/228010-jquery-disable-event/#findComment-1175793 Share on other sites More sharing options...
jcanker Posted February 18, 2011 Share Posted February 18, 2011 You're going about this the wrong way--address the final outcome, not the method to do it. What you said in your original post is essentially that you want to be able to revert the background color to its original color. The easiest and most direct way to do this is to assign a class to the dom element that you want to attach the color change to. That's just as simple as using .addclass() and .removeclass() in jQuery and styling the classes appropriately. Technically to ensure it's good in all browsers now and in the future, you'd want to assign a class in the HTML, then when you want to change the color, add the new class while removing the old one. When you want to change it back (when the link is clicked in your example) just removed the added class and add back the original one. Ensure both classes are styled appropriately in your css file and you're good to go. Quote Link to comment https://forums.phpfreaks.com/topic/228010-jquery-disable-event/#findComment-1175906 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.