Dynamically changing jQuery Mobile Buttons

Filed in the “In case you need to know” department, jQuery Mobile provides a basic API that allows you to modify buttons. This is more useful for creating new buttons, but also has uses for existing buttons. Specifically, I was looking for a way to swap out the theme of a button in a form based on what had been entered. Here is a simple example of this API in action:

Most of the template is boilerplate jQuery Mobile code. Note though the two buttons in the content section. Both are set to have no theme. Now - look at the JavaScript code at the bottom. I’ve got a basic click handler (should be touch I suppose) that will iterate over all possible theme values, including no theme specified. The API allows you to tweak pretty much everything, but I’m not sure what else you would change on the fly. Icon perhaps. Anyway, on the off chance someone needs this, here is a demo of the code above.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate for Extend by Auth0. He focuses on serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.

Lafayette, LA https://www.raymondcamden.com