Jquery raty is theres a way to callback the cancel button?

231 views Asked by At

Does anyone here who familiar with jquery raty?

is theres a way to callback the cancel button?

here's my code

$(".ratings").raty({
    cancel: function() {
        return $(this).attr("data-cancel");
    }
}); 

I want something like that. But my code seems not working.

1

There are 1 answers

1
ido On

Try using the code from my example below. You see a callback function for the click event. Because it will be executed on all clicks, you have to find a way to only execute some code when the cancel button is clicked. In my example you see this check is done based on the class name of the clicked element.

$(".ratings").raty({
    cancel : true,
    click  : function(score, evt) {
        alert("Score: " + score);

        // This is one way to check if you clicked the cancel button.
        if(evt.currentTarget.className === "raty-cancel")
        {
            // At this point we know you clicked the cancel button,
            // so insert code here to execute on callback.
        }
    }
});

In the callback function the alert("Score: " + score); returns null, so when it reaches this method, the score has already been removed due to clicking the cancel button.