Search code examples
jqueryevent-handlingjquery-click-event

Allow onclick just once


In order to add a very long list of option elements to a select list I add them on-click. I want to prevent that the list is added multiple times. How can I do that?

$("#skiresort").click(function(){
$("#skiresort").load("/v3/inc/review.php");
});

Solution

  • There is a method for executing an event handler only once: .one():

    $("#skiresort").one('click', function(){
        $("#skiresort").load("/v3/inc/review.php");
    });