Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

possible clear jquery `one` method

Its possible to clear jquery one property? for example given html

    <div id="button">button</div>

    <div id="clearOneProperty">clear one property</div>

and js

$("#button").one("click", function () {
    alert("blah");
});

$("#clearOneProperty").on("click", function () {
    // clear "one" property, that is after this event,  I want "#button"  to work again
});

Demo http://jsfiddle.net/RzzCu/2/

So, if click #button div, alert happened only one times right?

And I want that, at click on #clearOneProperty, reset one property. Its possible?

P.S. I am not asking how to make this with other ways, I am interest exact: "possible clear jquery one method?". Thanks.

like image 616
Oto Shavadze Avatar asked Nov 30 '12 09:11

Oto Shavadze


1 Answers

Try this:

function bindButton() {
    $("#button").unbind('click').one("click", function() {
        alert("blah");
    });
}

bindButton();

$("#clearOneProperty").on("click", function() {
    bindButton();
});

Updated fiddle

like image 89
Rory McCrossan Avatar answered Sep 29 '22 06:09

Rory McCrossan