Remove svg object

Asked

Viewed 106 times

1

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

example:

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

example jsfiddle: http://jsfiddle.net/twsthyds/12/

  • managed to make?

  • No jsddle works well, but in javascript without using jquery, it is also use remove()?

  • is that the browser does not work

  • cannot use with jquery?

  • No, the console says $ is not defined

  • I updated to do without jquery, see the new Fiddler I posted http://jsfiddle.net/rboschini/twsthyds/30/

  • worked now?

  • 1

    Gave, thanks @Rboschini

Show 3 more comments

1 answer

0


Hello, I updated your Fiddler, take a look.

I created a data-tag on the PAI images and I control who I exclude. The section below, I put 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.