Reputation: 10552
I am trying to get the ID of the image I am clicking on by using the following code:
theImg.on('click', function() {
alert($(this).attr('id')); //Should show 'IDofImg'
});
The Konva code is this:
var theImg = new Konva.Image({
image: imageObj,
x: stage.getWidth() / 2 - 200 / 2,
y: stage.getHeight() / 2 - 137 / 2,
opacity: 0.8,
shadowColor: 'black',
shadowBlur: 5,
id: 'IDofImg',
shadowOffset: {
x: 0,
y: 0
},
startScale: 1,
shadowOpacity: 0.6,
draggable: true
});
As you see, I have id: 'IDofImg', within the making of the image but it seems not to output the needed ID.
It currently outputs this when clicked on:
function() {
// setting
if (arguments.length) {
this[setter](arguments[0]);
return this;
}
// getting
else {
return this[getter]();
}
}
What am I missing?
Upvotes: 2
Views: 1734
Reputation: 10744
You should use this.id()
because it is the Konva Image object, and not an html/javascript
object.
See also the docs: http://konvajs.github.io/api/Konva.Node.html#id
Upvotes: 3