Lukas
Lukas

Reputation: 7744

Click disable for some time does't work with jQuery

I have this html element:

<div class="s_right hide_text"><a class="crackable" href="#">next</a></div>

and I need to disable click action on this element for some time, and i do this:

$.fn.disableFor = function (time) {
    var el = this, qname = 'disqueue';
    el.queue(qname, function () {
        el.attr('disabled', 'disabled');
        setTimeout( function () {
            el.dequeue(qname);
        }, time);
    })
    .queue(qname, function () {
        el.removeAttr('disabled');
    })
    .dequeue(qname);
};

var settings_rc_right = $('.s_right a');

settings_rc_right.on('click', function(){
    $(this).disableFor(2000);
    // actions
});

I don't know why but this still works, I can fast click one by one and click call action. Can anybody help me with this? Fiddle for this

Upvotes: 2

Views: 281

Answers (2)

user2032890
user2032890

Reputation:

Needs to apply a like this:

$("a").on("click," function(){ return !1; });
// or
$("a").on("mousedown" function(){ return !1; });

Upvotes: 1

jrummell
jrummell

Reputation: 43117

Only <input>, <textarea>, <select> and other form widgets support disabled. For other elements, you could add a disabled css class.

<a> needs to be handled differently. You could assign a click handler that does nothing:

$("a").click(function(){ return false; });

Also, you should be using .prop() instead of .attr(). See .prop() vs .attr().

Upvotes: 5

Related Questions