JSFiddle - React, Tailwind, and code Playground

by Gibrain Hernandez

HTML

<div class="button" id="test">Create File</div>

CSS

div.button {
	background: #fff;
	border: 1px solid;
	display: block;
	float: left;
	height: 30px;
	line-height: 30px;
	margin: 0 0 0 15px;
	padding: 0 10px;
	white-space: nowrap;
}

div.button:hover {
	background-color: #f0f0f0;
	background-position: 10px 10px;
	background-repeat: no-repeat;
}

JavaScript

$('body').on('click', '#test', function(event) {
        var link = document.createElement('a');
        // Add the element to the DOM
        document.body.appendChild(link);
        link.setAttribute("type", "hidden"); // make it hidden if needed
        link.download = 'test.xls';
        link.href = 'data:application/vnd.ms-excel;utf-8,test';
        link.click();
    });