How to disable an event and add a new one in jQuery

I'm having problems with a jQuery click event on a button inside a colorbox popup.

The button is as follows:

<div id="popup">
    <button class="close_bu">Close</button>
</div>

Which by default has the following event:

jQuery('.close_bu').bind('click',function(){        
            jQuery.colorbox.close();
});

When I fire another event, I want to change the default behavior, so I do the following:

jQuery('#anotherpopup').on('click','.deleteplan_button',function(){

            jQuery('#popup .close_bu').addClass('returnBack');
            jQuery('#popup .returnBack').removeClass('close_bu');

            jQuery.colorbox({inline:true , href:"#popup", opacity: 0.6, width: "600px"});
return false;
         })

And I added:

jQuery('#popup').on('click','.returnBack',function(){
                e.preventDefault();
                //Do something
})

But the new event attached to .returnBack does not work, and when I click the button, the close event is fired, it does not matter that the button does not have the .close_bu class, it continues to shell this event.

I'm a little confused: S

+3
source share
1 answer

There is no element with id in your code popup. Therefore, jQuery('#popup')nothing will be done (or you have not shown us the vital parts of the code).

Update:

. unbind()

$('#popup .close_bu').unbind('click');

'#popup .close_bu' , , . jQuery css css. css. , css, elment, .

+2

All Articles