Skip to content
Franco Mussopower pages
Code snippet

Drag & Drop Case Attachments – JavaScript for Dragover, Dragleave, Drop

Copy it with the button on the code. For the why and the walkthrough, see “Create a Drag and Drop experience to upload Case Attachments in Power Pages”.

Drag & Drop Case Attachments - JavaScript for Dragover, Dragleave, DropJavaScript
$(document).ready(function() {
    
    // Initialise a variable that references the "drop-zone" container defined in the HTML
    var dropZone = $('#drop-zone');
 
    // Add a dragover event listener to the dropZone
    dropZone.on('dragover', function() {
        // Add a class of 'dragover'. We'll use this to provide visual feedback
        $(this).addClass('dragover');
        return false;
    });
 
    // Add a dragleave event listener to the dropZone
    dropZone.on('dragleave', function() {
        // Remove the'dragover' class. We'll use this to provide visual feedback
        $(this).removeClass('dragover');
        return false;
    });
 
    // Add a drop event listener to the dropZone. This is our key event
    dropZone.on('drop', function(e) {
        // Prevent the default behavior of opening the file in the browser
        e.preventDefault();
        // Remove the'dragover' class. We'll use this to provide visual feedback
        $(this).removeClass('dragover');
    });
});

Search

Book a discovery call

30 minutes. Bring your trickiest Power Pages problem — I’ll tell you honestly whether I’m the right fit.