I have what is likely a simple problem, whereby I am trying to get a jquery mobile button to be disabled upon page initialization, with the following:
<body>
<section id="firstpage" data-role="page-content">
<header data-role="header">
<h1>Working with Buttons</h1>
</header>
<div data-role="content">
<p>This is a <button> element:</p>
<button id="btn1">button element</button>
</div>
</section>
<script>
$("#firstpage").live('pageinit', function (evt) {
$("#btn1").button("disable");
});
</script>
</body>
The page loads with all the jquery mobile formatting and behaviors as expected, but the button remains enabled. Any ideas? What very simple detail am I missing here?
Just add the
disabled=trueattribute. jQuery Mobile will read that attribute and initialize the widget as disabled.Here is a demo: http://jsfiddle.net/CDYgD/
Also,
data-role="page-content",page-contentis not a valid jQuery Mobiledata-rolefor a pseudo-page element, it should be justpageunless you’ve made some type of customization. Docs for this: http://jquerymobile.com/demos/1.1.0-rc.2/docs/api/data-attributes.html (look forPageheader)