Check if input is disabled and then alert but something is wrong

http://jsfiddle.net/gxu3q09a/2/

As there just detect that is not disabled but how is that possible when disabled with jQuery and also set on html side a disabled attribute?

So how can detect if this disabled on mousedown and display an alert. Why is got from else alert message?

Thanks!

Since disabled control elements can’t have events bound to them, you’d need to bind an event to an ancestor element and make a check to see whether the target was the input.

You can then go on to check if it’s disabled, and if so, show your alert:

$(document).ready(function() {  
  $(document).on('mouseup', function(e){
      if(e.target.id == "fileInput" && e.target.disabled){
        alert('CLICKED, BUT DISABLED!!');
      }else{
            alert('Not disabled. =)');
      }
  });
});

Now, this test is done using a type = "text", in your case with the type = "file", there is a problem.

input[type=file] is very peculiar input type, you can’t really do a whole lot with it, primarily for security reasons.

I hope I have helped

1 Like