2

For an input extension script I'm making I need an input to tell me when/if it gets disabled. That is, when it's disabled parameter is set.

Is there an event for this?

If not, how would I emulate the behaviour?

Also I'm using jQuery

1
  • What will be disabling the input? It is going to be some other part of your script? Commented Aug 17, 2011 at 16:00

3 Answers 3

3

Ideally, any events that you need to latch on to (and aren't user events - click, mouseover etc.) should be fired programmatically within the code, as opposed to polling the actual DOM, which is the end-representation that your code produces.

DOM mutation events aren't well supported and AFAIK are being deprecated.

From the sounds of what you've said, it seems like the best thing to do would be to check whether the <input> is disabled upon initiation of your extension/plugin, and then enable plugin/extension users to disable the input via your own API, meaning that you can know when it happens.

A really primitive example would be creating your own disable method for jQuery:

jQuery.fn.disable = function() { return this.each(function(){ $(this).attr('disabled', true).triggerHandler('disable'); }); }; // E.g. var input = jQuery('input#foo'); input.bind('disable', function(){ alert('Foo Disabled!'); }); input.disable(); 

You can see that we trigger our own event for each element within the disable method. This is just an example though; I don't really suggest this -- try to keep everything under the namespace of your own plugin/extension.

Sign up to request clarification or add additional context in comments.

Comments

0

I am afraid there is no built-in event like that. Using trigger and bind, however, you can create your own event. Custom events in jQuery?

Comments

0

I hope using .attr() you can find its disabled or not

1 Comment

Finding it is not the issue - detecting when it CHANGES is.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.