Daolin
Daolin

Reputation: 634

Html and javascript: how to switch download link to button

I have a export to excel link on my page like:

<a download="queryResults.csv" href="#" onclick="return ExcellentExport.csv(this, 'datatable');">Export to CSV</a>

I would like to present it as a button, I tried something like:

<button download="queryResults.csv" href="#" onclick="return ExcellentExport.csv(this, 'datatable');">Export to CSV</button>

Hoe should I get it to work? Thanks.

Upvotes: 0

Views: 266

Answers (2)

Danyal Sandeelo
Danyal Sandeelo

Reputation: 12391

 <a download="queryResults.csv"  
   onclick="return ExcellentExport.csv(this, 'datatable');" href="#"> 
   <button>Export to CSV</button>
 </a>

Upvotes: 2

Philip
Philip

Reputation: 21

The button element has no href attribute. Instead you have to provide a type attribute, which has to be type="button". See the specs here: HTML button tag

Upvotes: 0

Related Questions