I have a jQuery Mobile Beta 1 website with jQuery 1.6.1 link button like this:
<a id="subselection" href="#" data-role="button" data-theme="b">TEST</a>
And in document.ready i set the click event:
$('#subselection').livequery("click", function(){
alert('test');
});
I whant to disable this "link button" and i tried
$('#subselection').button('disable')
And that command set the button style like it is disabled but the click event works.
I have also tried
$('#subselection').prop('disabled', true);
and $('#subselection').prop('disabled'); gives true but its not disabled.
Someone has a good idea.
Link button example:
JS
HTML
NOTE: - http://jquerymobile.com/demos/1.0rc2/docs/buttons/buttons-types.html
try using
this seems to work visually to display a disable / enable style...HOWEVER the "button" is still clickable (so watch out! :P )
I know there's already an accepted answer to this, but I think this answer is much easier to understand. Just have the click function return false.
The
a
element does not have a propertydisabled
. So defining one won't affect any event handlers you may have attached to it.example: http://jsfiddle.net/niklasvh/n2eYS/
For a list of available attributes, have a look at the HTML 5 reference.
To solve your problem, you could instead for example assign the
disabled
asdata
in the element:$('#subselection').data('disabled',true);
and then in your event check if its set:
if (!$(this).data('disabled'))
example: http://jsfiddle.net/niklasvh/n2eYS/5/
No need for jquery/javascript in this case. Simply add a 'ui-disabled' class.
Like for example:
Thats what I do, and it works for me ;)
You could alternatively just use the button tag/widget directly
<button>TEST</button>
which does have proper disabling. If you are just using it to catch an event and run some JavaScript not sure what advantage there would be in using a link.