Search code examples
javascriptimagekineticjs

How to change id of image using kineticjs


First i create an image with id:image1.then i want to change the id image1 into image2 and create new image with the id:image1...I tried but it is not working.can anyone help me?

            var image = new Kinetic.Image({
                    name: data,
                    id: "image1",
                    x: stage.getWidth()*0.5-20,
                    y: stage.getHeight()*0.5-125,
                    width:20,
                    height:250,
                    image: theImage,
                    draggable: false
                });
         image.setId("image2");
         var image = new Kinetic.Image({
                        name: data,
                        id: "image1",
                        x: stage.getWidth()*0.5-200,
                        y: stage.getHeight()*0.5-125,
                        width:20,
                        height:250,
                        image: theImage,
                        draggable: false
             });

Solution

  •       var kk=stage.find("#image1")[0];
          kk.setId("image2");