Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting attribute disabled on a SPAN element does not prevent click events

I have a <span> element which does something on a click event.

When I disable it, using jQuery:

$("span").attr("disabled", true); 

The event handler continues to be called when I click on the span element.

I am testing in Chrome 13. Any thoughts?

like image 366
Petar Maymounkov Avatar asked Jul 11 '11 22:07

Petar Maymounkov


People also ask

Does span have disabled attribute?

The disabled attribute is not global and is only allowed on form controls. What you could do is set a custom data attribute (perhaps data-disabled ) and check for that attribute when you handle the click event.

What are attributes in span tag?

Definition and Usage The span attribute defines the number of columns a <col> or <colgroup> element should span.

What is the use of SPAN attribute in HTML?

<span>: The Content Span element The <span> HTML element is a generic inline container for phrasing content, which does not inherently represent anything. It can be used to group elements for styling purposes (using the class or id attributes), or because they share attribute values, such as lang .

Does span tag has value attribute?

Attribute Values: It contains the numeric value which specifies the number of supported element should span.


2 Answers

Try this:

$("span").css("pointer-events", "none"); 

you can enabled those back by

$("span").css("pointer-events", "auto"); 
like image 110
David Espino Avatar answered Sep 21 '22 00:09

David Espino


The disabled attribute is not global and is only allowed on form controls. What you could do is set a custom data attribute (perhaps data-disabled) and check for that attribute when you handle the click event.

like image 44
You Avatar answered Sep 20 '22 00:09

You