How to bind click event to object tag?

The easiest way to accomplish this goal is to wrap the object tag in a div, bind the click listener to the div, and add pointer-events: none to the object tag’s styles.

Sample fiddle:

.clickable {
  background: red;
  width: 100px;
  height: 100px;
  border-radius: 100px;
  overflow: hidden;
}

object {
  width: 100%;
  pointer-events: none;
}
<div class="clickable" onclick='alert("WOW")'>
  <object type="image/svg+xml" data="https://douglasduhaime.com/assets/images/icons/home.svg" />
</div>

Leave a Comment