Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable onfocus event for svg element

I realized that tabindex=-1 doesn't work for <svg></svg> elements. Is there a way to disable the focus event for it? preventDefault, stopPropagation, stopImmediatePropagation also do not work.

like image 374
Shalom Aleichem Avatar asked Sep 05 '13 21:09

Shalom Aleichem


People also ask

How do I disable SVG element?

Just use $(". dasvg")[0]. setAttribute("class", "disabled") assuming that the element doesn't have any classses already.

Is SVG focusable?

In SVG only the element <a xlink:href="…"> is considered naturally focusable by all browsers.

How do you make an element not focusable?

In order to make an prevent an element from taking focus ("non-focusable"), you need to use Javascript to watch for the focus and prevent the default interaction. In order to prevent an element from being tabbed to, use tabindex=-1 attribute. Adding tabindex=-1 will make any element focusable, even div elements.

Is SVG an HTMLElement?

SVG elements are actually of type HTMLElement .


1 Answers

<svg focusable="false"></svg> does this job.

like image 100
Shalom Aleichem Avatar answered Sep 20 '22 05:09

Shalom Aleichem