0

I'm using dropzone.js. Is there a way I can get the filename on the click event of removefile? I was thinking of getting the filename from dz-filename's IMG alt and remove the image from the database and server. If there's another way that'd be great too!

But this is what I have and it gives me undefined as the name:

<div class="dz-preview dz-image-preview">  
  <div class="dz-details">    
    <div class="dz-filename">
      <span data-dz-name="">d24baa48eb1b8ed17755796425141fdc.jpg</span>
    </div>    
    <div class="dz-size" data-dz-size="">
      <strong>9</strong> KiB
    </div>    
    <img data-dz-thumbnail="" alt="d24baa48eb1b8ed17755796425141fdc.jpg" src="/images/thumbnail/d24baa48eb1b8ed17755796425141fdc.jpg">
  </div>
  <a class="dz-remove" href="javascript:undefined;" data-dz-remove="">Remove file</a>
</div>

I also tried: siblings, find and closest.

this.on("removedfile", function(file) {
  var name = $(this).parent(".dz-image-preview")
               .siblings(".dz-details").children("img").attr("alt");
  alert(name);
});
noahnu
  • 3,479
  • 2
  • 18
  • 40
hammies
  • 1,344
  • 2
  • 22
  • 46

1 Answers1

0

From that bit of your code, I believe $(this) is something inside <div class="dz-preview dz-image-preview">. So from that assumption you can get the alt by doing this:

$(this).parents(".dz-image-preview").find("img").attr("alt");
Bla...
  • 7,228
  • 7
  • 27
  • 46