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.
<a download="queryResults.csv"
onclick="return ExcellentExport.csv(this, 'datatable');" href="#">
<button>Export to CSV</button>
</a>
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
Related
I have several dynamically created links which rendered as buttons and the buttons texts are replaced with icons. I need to toggle one of the link button icons when clicked. The method that I am using is not working out. See code below: I do not want to use JQuery at this time unless it’s within a function.
<a class="button" onclick="command('removeFormat');" title="Remove Format"><i class="fas fa-eraser"></i></a>
<a class="button" onclick="command('fullScreen');" title="Full Screen"><i class="fas fa-expand"></i></a>
<a class="button" onclick="doToggleView();" title="Source"><i class="fa fa-code"></i></a>
<a class="button" onclick="submitForm();" title="Save"><i class="far fa-save"></i></a>
//JS
function command(cmd){
if(cmd == 'fullScreen'){
$(".fa-expand").toggleClass('fa-expand fa-compress');
}else{
$(".fa-compress").toggleClass('fa-compress fa-expand');
}
}
I also try using the following codes:
$("i").toggleClass('fa-compress fa-expand');
$("a .button").find("i").toggleClass('fa-expand fa-compress');
This is the fix to resolve the issue.
function command(cmd){
$('i.fas').toggleClass('fa-expand fa-compress');
}
i´ve got the following code in my website:
<a class="jr-btn jr-btn-success " data-action="sendStep"> Senden </a>
I want to do the data-action called by a javascript-function. Is it possible?
Yes it is possible, and you would use the .getAttribute('data-action') to get the value
console.log(document.getElementsByClassName("jr-btn-success")[0].getAttribute('data-action'))
<a class="jr-btn jr-btn-success " data-action="sendStep"> Senden </a>
I need that use href="" attribute for button
like this <button href="link">click me</button> Instead of <a href="link">
that's wrong .
I think that I've to try this code
<button onClick="FN('MY Link For Example www.stackoverflow.com')" >click me</button>
<script>
function FN('URL'){
--> Go to MY Link For Example www.stackoverflow.com
}
<script>
So what do u guys suggest I should do ?
Try this. This will navigate to the link on click.
<button onclick="window.location.href='http://www.stackoverflow.com'">click me</button>
Why you don't use <a type="button" href=""></a>
Or if you really want a button, so <button onclick="window.location.href=""></button>
I think this will solve your problem
<a href="http://www.stackoverflow.com/">
<button>click me</button>
</a>
href attribute can not be used on button tag , if you want button like appearance for your a tag you can use add style to your a tag and make it look like button , add bootstrap reference then add button class to your anchor tag.
Custom Bootstrap Button , but if you still want to use button tag then adding onclick event is better option
I have an HTML element:
<a id="link" href="javascript : void(0);" onclick="jsFunction();">Some Text</a>
And when a button is clicked I want the onclick attribute to be cleared. Something like
<a id="link" href="javascript : void(0);" onclick="">Some Text</a>
I tried doing this way :
document.getElementById('link').onclick="";
which didn't work.
Use removeAttribute()
document.getElementById('link').removeAttribute('onclick');
SEE DEMO
I currently have this code:
<input id="doCheck" type="button" onclick="doCheck('a'); return false;" />
But I want to convert this to use an address link and not an input because I have created my own class btn and I want to use that.
<a class="btn" href="#(Model.NextUrl)" title="Go to next">>></a>
Is it possible to do this. To make the clicking on the link activate Javascript. Also can I stop Google from getting interested in the address?
sure, you can add the onclick to the anchor:
<a class="btn" href="#(Model.NextUrl)" title="Go to next" onclick="doCheck('a'); return false;">>></a>
Link text
the onclick can be used here
rel="nofollow" will tell google jnot to 'click' the link
Yes, you can. The onclick attribute may be used with most elements.
<a class="btn" href="#(Model.NextUrl)" onclick="doCheck('a'); return false;"
title="Go to next">>></a>
By adding the onclick to your hyperlink, you avoid Google from tracking the address of the link since the JavaScript is not contained in the href. Either way, Google doesn't track JavaScript in hrefs anyway.
<a class="btn" href="#(Model.NextUrl)" title="Go to next"
onclick="doCheck('a'); return false;">>></a>
Alternatively, you can add a rel tag to any anchor that tells Google not to track the address of the hyperlink:
<a class="btn" href="#(Model.NextUrl)" title="Go to next"
onclick="doCheck('a'); return false;" ref="nofollow">>></a>