JavaScript Add listener to a svg element which is imported in canvas

I need to add event listeners on a canvas elements (I know they are not actually elements). I've understood that this is possible only with svg. So I imported some svg elements into the canvas following the example given here. And this is what my code looks like:

var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var canvas = document.getElementById('myCanvas');
var ctx = canvas.getContext('2d');
//wherever I put the id inside the svg element it does not fire the event
var data = '<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200">' +
       '<foreignObject width="100%" height="100%">' +
       '<div id="asdf" xmlns="http://www.w3.org/1999/xhtml" style="font-size:40px">' +
         '<em >I</em> like ' + 
         '<span style="color:white; text-shadow:0 0 2px blue;">' +
         'cheese</span>' +
       '</div>' +
       '</foreignObject>' +
       '</svg>';
var DOMURL = window.URL || window.webkitURL || window;
var img = new Image();
var svg = new Blob([data], {type: 'image/svg+xml;charset=utf-8'});
var url = DOMURL.createObjectURL(svg);

img.onload = function () {
   ctx.drawImage(img, 0, 0);
   DOMURL.revokeObjectURL(url);
}
img.src = url;
document.getElementById('asdf').addEventListener("click", function(){
    alert('AJDEEE');
});

If I attach the listener to the canvas it works. But when it is attached to an element inside the svg it does not. So am I wrong anywhere or it is just impossible that way ? Any help will be highly appreciated.

Answer:1

here is a simple problem I can't find a solution to. I have a typeahead directive in input which lets a user to choose a category ( category array example -> [{ id: 1as1d, name: 'some category'},...] ...

here is a simple problem I can't find a solution to. I have a typeahead directive in input which lets a user to choose a category ( category array example -> [{ id: 1as1d, name: 'some category'},...] ...

  1. bootstrap typeahead with ajax call
  2. bootstrap typeahead with multiple values
  3. bootstrap typeahead with image
  4. bootstrap typeahead with ajax
  5. bootstrap typeahead with scrollbar
  6. bootstrap typeahead with dropdown
  7. bootstrap typeahead with dropdown button
  8. bootstrap typeahead with links
  9. bootstrap typeahead with static data
  10. bootstrap typeahead with database
  11. bootstrap typeahead with angularjs
  12. bootstrap typeahead with headers
  13. bootstrap typeahead in modal
  14. bootstrap typeahead in mvc
  15. bootstrap typeahead in asp.net webforms
  16. ngx bootstrap typeahead with objects
  17. ngx-bootstrap typeahead with http
  18. ng-bootstrap typeahead with objects
  19. ngx-bootstrap typeahead with observable
  20. bootstrap select with typeahead

I am trying to make a real time application. I am using NodeJS as a server and Socket.IO, to achieve my real time functionality. The problem is I am getting error as: WebSocket connection to 'wss://...

I am trying to make a real time application. I am using NodeJS as a server and Socket.IO, to achieve my real time functionality. The problem is I am getting error as: WebSocket connection to 'wss://...

  1. invalid frame header websocket
  2. invalid frame header websocket chrome
  3. invalid frame header headeru003d'' syslog-ng
  4. invalid frame header socket.io
  5. invalid frame header syslog-ng
  6. invalid frame header chrome
  7. invalid frame header signalr
  8. failed invalid frame header
  9. failed invalid frame header websocket
  10. ws invalid frame header
  11. failed invalid frame header socket.io
  12. syslog invalid frame header
  13. socket invalid frame header
  14. sockjs invalid frame header
  15. websocket invalid frame header
  16. flac invalid frame header
  17. websocket connection invalid frame header
  18. sockjs-node invalid frame header
  19. nginx websocket invalid frame header
  20. websocket error invalid frame header

I have the following express app which just renders the sample.ejs page. On that page when I press the button the attached script changes the div text to "THIS IS FROM J QUERY. I want the same thing ...

I have the following express app which just renders the sample.ejs page. On that page when I press the button the attached script changes the div text to "THIS IS FROM J QUERY. I want the same thing ...

  1. update part of html page
  2. update only part of html page

I want to access the variable "blocks" of my objects.. this is possible, if i use the name ot the function print, but is not possible if i use print as a callback. what am i doing wrong? how can i use ...

I want to access the variable "blocks" of my objects.. this is possible, if i use the name ot the function print, but is not possible if i use print as a callback. what am i doing wrong? how can i use ...

  1. javascript node this