flex_ flex_ - 1 month ago 5
Javascript Question

removeProp() not working

I 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 a problem with phpstorm, but 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.remove('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