Jul 14, 2021
How to make all HTMLElements inside an <button> tag clickable?
Simple css solution is to disable pointer event of all other HTMLElements inside a button. This way only the button gets clicked no matter where you as a user click.
<button>
<svg> <use xlink:href=”#gear”></use> </svg>
</button>
In the above code, clicking on svg does not means onClick event for the button will be triggered. If we use the simple css solution mentioned below, a click on svg element will trigger onClick event for the button.
button > * {
pointer-events: none;
}