2

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

tshepang
  • 12,111
  • 21
  • 91
  • 136
Lukas
  • 7,384
  • 20
  • 72
  • 127

2 Answers2

5

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().

Community
  • 1
  • 1
jrummell
  • 42,637
  • 17
  • 112
  • 171
  • return false; is a little bit old-fashioned as I know, and not recommended to use in this case. Check this documentation: http://fuelyourcoding.com/jquery-events-stop-misusing-return-false/ Probably it's much better to use here: $("a").click(function(event) { event.preventDefault(); }); – tildy Feb 01 '13 at 15:53
  • Assuming the OP wants to disable all click handlers and event propagation, `return false` is appropriate here. – jrummell Feb 01 '13 at 16:02
1

Needs to apply a like this:

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