You cannot delete files using javascript for security reasons . Bad guys can delete your stytem files :( However, you can do this with a combination of a server language such as PHP, ASP.NET, etc., Using what is known as Ajax .
Note. Javascript goes on to add / bid on the server. Node JS is an example of this.
Comment based update:
You can delete files something like this:
<a href="#" class="delete">Delete</a>
JQuery
$(function(){ $('a.delete').click(function(){ $.ajax({ url:'delete.php', data:'id/name here', method:'GET', success:function(response){ if (response === 'deleted') { alert('Deleted !!'); } } }); }); });
PHP:
if (isset($_GET['id/name here'])) { if (unlink('your_folder_path' . $_GET['id/name here'])) { echo 'Deleted'; } }
source share