Remove object svg

1

I have the following code that creates a clone of an image. When, for example, you hear 3 clones, delete the last one. Without appearing.

example:

if (id==3){
 //apagar clone/imagem
}

jsfiddle example: link

    
asked by anonymous 15.01.2016 / 13:03

1 answer

0

Hello, I updated your fiddler , take a look.

I created a date-tag in the PAI images and with that I control who I delete. The section below, I placed at the end of the method function mousedown(e) .

  var type = ddData.element.getAttribute('data-type');
  var arrTmp = document.querySelectorAll('[data-type="'+type+'"]');

  if(arrTmp.length>3){
    var el = arrTmp[0];
    el.parentNode.removeChild( el );
  }

How did the html

<svg width="90%" height=500px>
    <image data-type="img1" xlink:href=/favicon.png id=img1 x=0 y=0 height=20 width=20 class="img" />
    <image data-type="img2" xlink:href=/favicon1.png id=img2 x=30 y=0 height=20 width=20 class="img" />
</svg>

See if it helps

    
15.01.2016 / 13:20