Enable vs Disable – jQuery Mobile

How to enable and disable various components in jQuery Mobile? Following are my tips.

  • Button

To disable a button, simply add the ‘disabled‘ attribute to it:

Or you’d like to manipulate the button component via Javascript:

The same applies to a submit button. Adding the ‘disabled‘ attribute to the submit button disables it.

Or we’re able to manipulate the submit button via Javascript:

As far as link button is concerned, since anchors don’t natively have any disabled state, jQuery Mobile group decides not to support disable and enable anchors like buttons. Therefore, we have to apply ‘ui-disabled’ class to the anchor to achieve the same effect.

Here’s how to do via Javascript:

  • Form 

It’s extremely easy to disable form components by just adding ‘disabled‘ attribute to them.

The display looks like below:

To implement it via Javascript:

Or we’re able to disable the entire form by adding ‘ui-disabled‘ class to it:

Through this way, the labels inside the form are dimmed too.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s