I want to get the id of the svg-element (text) which has been hovered. The HTML:
<svg class="compass-svg" width="200" height="200">
<text id="textN" x="93" y="55" fill="#000">N</text>
<text id="textE" x="145" y="105" fill="#000">O</text>
<text id="textS" x="95" y="158" fill="#000">S</text>
<text id="textW" x="40" y="105" fill="#000">W</text>
</svg>
This is the javascript code:
$('text').hover(() => {
//this is not working
console.log($(this).attr('id'));
//this is also not working
console.log(this.attr('id'));
//I've also tried this
console.log(this.id);
});
When I hover for example the first text element it should write 'textN' to the console.