0

When can I make the object clickable.

For example:

<object data="img/test.svg" type="image/svg+xml" />

When I add onclick it doesn't work.

Important notice: I need to have an object and not img, due to the fact that I'm making some manipulation to the svg once that it is loaded.

Elisha Sterngold
  • 2,324
  • 1
  • 16
  • 14

2 Answers2

0

You could add click event programatically?

Like this:

<object id="svgId" data="img/test.svg" type="image/svg+xml" />

var el = document.getElementById("svgId").onclick=yourMethod;


yourMethod()
{
   // Your method which would do something when it's clicked?
}

Or a el .addEventListener("click", yourMethod, false);

Roxy'Pro
  • 4,216
  • 9
  • 40
  • 102
0
document.getElementById("svg").addEventListener('click', doSomething);

function doSomething(e) {
  // code
}
WASD
  • 310
  • 1
  • 9