Jquery: live () - live only once?

I follow this topic to disable / enable click on a button. Best way to remove an event handler in jQuery?

his idea is that you can also use the live () method to enable / disable events. What happens with this code is that when you click on a tag element, such as .load-item, it will add a class that is disabled for this element. This will cause the selector to no longer match the element, and the event will not be fired until the "disabled" class is deleted, again making the .live () selector valid.

Below is what I went out with and it disables the pressing of the first button,

$('.load-item:not(.disabled)').live('click',function(){


/* add a .current class to the target item */
$(this).parentsUntil('.column-global').addClass('current');

/* add .disabled class to each a tag in the .current element-div */
$('.current a').each(function(index) {
    $(this).addClass('disabled');
});

....

});

and I have another function to remove a disabled class when you click on another button,

$('.button-return').click(function(){

    ...

    /* remove all the .disabled class if any exists */
    $('.current a').each(function(index) {
        $(this).removeClass('disabled');
    });

    ...

    /* remove all the .current class if any exists */
    $('.item-global').removeClass('current');



    return false;

});

, , , .

- - live() ? , live() , ?

.

+3
2

$('.button-return:not(disabled)').live("click",function(){...});

addClass() removeClass() . .

$('.current a').each(function(index) {
    $(this).removeClass('disabled');
});

$('.current a').removeClass('disabled');

Edited

, , , .

, http://www.jsfiddle.net/Qax3n/

+1

- HTML Javascript. : http://jsfiddle.net/EEJEh/

0

Source: https://habr.com/ru/post/1772965/


All Articles