简体   繁体   中英

How to add an event on SVG click with Meteor?

I have a SVG and I want to add an event listener on it.
My structure is the following one:

<template name="dataGraph">
  <div style="height: 100%;" class="right_col" role="main">
    <div id="logoObject">
      <object id="svg_compose" type="image/svg+xml" data="output.svg">Your browser does not support SVGs</object>
    </div>
  </div>
</template>

and in my JavaScript I did:

Template.dataGraph.onCreated(function dataGraphOnCreated() {
});

Template.dataGraph.onRendered(function dataGraphOnRendered() {
  $(document).on('click','svg',function(){
        alert('You clicked me svg');
  });

  $(document).on('click','#svg_compose',function(){
        alert('You clicked me svg_compose');
  });

  $(document).on('click','#logoObject',function(){
        alert('You clicked me logoObject');
  });
});

Template.dataGraph.events({
  'click #svg_compose': function(e){
    console.log("we are in the svg element");
  }
});

and the only listener who works is the one of #logoObject

在此处输入图片说明

My goal is to print the content of <text> when we click on the element.

Could you help me to get that because I'm trying and trying and trying...

最终我了解到我们不能将事件与<object>一起使用,所以我使用了https://github.com/madebyshape/svg-convert

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM