Disable an HTML element, but not a form element
Is there a way to disable an HTML element with jQuery that it's not a form element?
For example:
<ul class="selectors">
<li class="clear-selected">Clear Selected<span> </span></li>
<li class="select-all">Select All<span> </span></li>
</ul>
Can I 'disable' the LI "clear-selected"?
What I'm trying to do is so that that LI can't be clicked on.
I've tried something like this but it doesn't work:
$('#x').attr('disabled', true);开发者_开发问答
http://docs.jquery.com/FAQ#How_do_I_disable.2Fenable_a_form_element.3F
Thanks,
EDIT--
This question is part of a bigger case, here's the Main Question.
Thanks to everyone that answered.
Well, by default nothing happens if you click on an li-element. I guess, you have click-handlers attached to your elements, that perform the described actions. In this case, you could just unbind these handlers to "disable" the elements.
If all you want to do is disable the event handler for the element, you can do that like this:
$(".clear-selected").click(function() {
return false;
});
When you say "so that LI can't be clicked on", what do you mean by that? Do you have an onclick handler on that element? If so, you can simply remove the handler.
You could use either of these:
$(".clear-selected").hide();
$(".clear-selected").remove();
Edit: I think I read your question wrong.
What happens when they click the li
? Can't really help you make the event stop if we don't know what it is.
Since this question is part of a more complex case, here's the link to that solution: Buttons activate/deactivate elements in list (complex case)
Here's the jsfiddle DEMO, notice how the "Clear Selected" button has no click action. It's 'faded' using opacity to convey the idea of 'inactive'.
Thanks.
精彩评论