flex_ flex_ - 2 months ago 19
Javascript Question

removeProp() not working in jquery

so i basically have an input and i want to disable it but it doesn't work at all. even phpstorm says the function doesn't exist for some reason.. i thought it's problem with phpstorm but nope i tried it in chrome and it doesn't work.. is there any alternative or am i doing something wrong? i must point out that button.css('pointer-events', 'none'); works but removeProp doesn't for some reason..

function waitComment() {
var button = $(".btn-primary");
button.css('pointer-events', 'none');
setTimeout(function(){
button.removeProp('pointer-events');
}, 3000)
}




<input type="submit" class="btn btn-primary" value="Comment" name="comment" id="#comment" class="comment" onclick="waitComment()">

Answer

The proper way to achieve your goal is,

CSS

.pointer{
    pointer-events: none;
}

Jquery:

function waitComment() {
    var button = $(".btn-primary");
        button.addClass('pointer');
    setTimeout(function(){
        button.removeClass('pointer');
    }, 3000)
}

Why .removeProp() didn' work?

Jquery .removeProp() is for Html attributes/properties not for CSS properties.

Please find the Api reference of .removeProp

Comments