Here,How to disable this link by using button tab?Is it possible?
<a href="http://www.google.com">
<button>click here for go to yahoo</button>
</a>
To disable a HTML anchor element with CSS, we can apply the pointer-events: none style. pointer-events: none will disable all click events on the anchor element. This is a great option when you only have access to class or style attributes. It can even be used to disable all the HTML links on a page.
Answer: Use the jQuery removeAttr() method You can easily remove the clickable behavior from a link through removing the href attribute from the anchor element ( <a> ) using the jQuery removeAttr() method.
$('#buttononclickdisable'). click(function(){ $('#disableanchor'). attr("disabled","disabled"); });
To prevent an anchor from visiting the specified href, you can call the Event interface's preventDefault() method on the anchor's click handle.
Give ids and disable at the run-time.
HTML:
<a id="disableanchor" href="http://www.google.com">
<button id="buttononclickdisable">click here for go to yahoo</button>
</a>
Javascript:
$('#buttononclickdisable').click(function(){
$('#disableanchor').attr("disabled","disabled");
});
Or remove the 'click' event listener.
$("#anchorid").off('click');
Surprisingly it is not such a straightforward task since anchor tags do not have a disabled attribute (on the contrary of input tags, select tags, textarea tags, etc.).
The workaround I often use is first to define a class with pointer-events set to none (CSS):
.disable-click{
pointer-events:none;
}
Then I use Jquery (1.0+) to disable/enable the "clickability" of the anchor tag in question by adding/removing the class previously defined:
$("#my-a-tag-id").addClass("disable-click");
$("#my-a-tag-id").removeClass("disable-click");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With