I'm trying to make download function (only where checkbox checked can be downloaded and download function is already done).
when I check only one, It works fine. download well
but I want to check many and download too.
I set download_file() works only one at a time in need
download_file() is onClick event and execute by this way
d_tr.querySelector('.test > a').click();
what I want is execute another function after first one finished.
It doesn't matter Javascript or Jquery.
js $(document).ready(function () { $(".compress").click(function () {
    var size = document.getElementsByName("check").length;
    for(var i = 0; i < size; i++){
        if(document.getElementsByName("check")[i].checked == true){
            var d_val=document.getElementsByName("check")[i].value;;
            var d_td = document.getElementById(d_val);
            var d_tr = d_td.parentElement;
            d_tr.querySelector('.test > a').click();
            $.when(d_tr.querySelector('.test > a').click()).done(function () {
               console.log("finished");
            });
        }
    }
    });
});
var oneClick = true;
function download_file(event, filename) {
    if (oneClick) {
        oneClick = false;
        req = request({
            method: 'GET',
            uri   : fileURL,
        });
        var out = fs.createWriteStream(finalPath);
        req.pipe(out); 
        req.on('response', function (data) {
            console.log();
        });
        req.on('data', function (chunk) {
             console.log();
        });
        req.on('end', function () {
            oneClick = true;
            document.getElementById(subW).onclick = null;
        });
    }
    else {
        alert('somethins is downloading');
    }
}
html
<tr>
  <td id="10Mb.dat"><input type="checkbox" name='check' value='10Mb.dat'/>File10MB
  </td>
  <td class="test"><a class="checkBtn checkBtn1" id="checkBtn1" onclick="download_file(event, '10Mb.dat')">download</a></td>
</tr>
<tr>
  <td id="100mb.bin"><input type="checkbox" name='check' value='100mb.bin' />File100MB
  </td>
  <td class="test"><a class="checkBtn checkBtn2" id="checkBtn2" onclick="download_file(event, '100mb.bin')">download</a></td>
</tr>
 <button class="btn btn-primary compress">download start</button>