Disabling the button of an anchor tag

disable anchor tag javascript
how to enable and disable href in javascript
disable anchor tag html
disable anchor tag angular
disable anchor tag onclick javascript
javascript disable link'' onclick
w3schools disabled link
disable href style

I have a button inside the anchor tag(defined it using class).

<a id="moreButton" class="contactButtonSmall" style="position:absolute; left:225px; top:165px;  FONT-WEIGHT:normal; FONT-SIZE:11pt;" onclick="doSomething();">More</a>

Now I want to disable it.So I have used the following code to disable the anchor tag.

moreButton.disabled = true;

The anchor tag is not working after disabling it , but the button of anchor still looks as if it is not disabled i.e. not grayed out. Is there any way to disable the button? Please let me know if you need any additional information.

As others have said, inline CSS is bad practice so you should export your style code to a separate CSS file, as so:

.contactButtonSmall {
  position:absolute;
  left:225px;
  top:165px; 
  font-weight:normal;
  font-size:11pt;
}

Then you can use the :disabled selector to change the appearance of the button when it is disabled:

.contactButtonSmall:disabled {
  /* Styling for disabled button */
}

How to Disable Links, How do I disable an anchor tag link in HTML without using the pointer-events: none; and How do I link a submit button to another webpage using HTML? <a> tag is supported by almost all web browsers. This post will guide you to disable Anchor tag in HTML, CSS, and Javascript. How to Disable Anchor Tag in HTML? To disable Anchor tag in HTML, there is a simple code, but that doesn’t work in modern day browsers. It worked with Internet Explorer.

The best way to disable an anchor tag is to give it the correct pointer-events property. Here's a simple example how to disable the anchor tag with one simple CSS line:

a {
  pointer-events: none;
}
<a href="https://google.com">I am a disabled anchor tag</a>

How to disable an anchor tag link in HTML without using the pointer , jQuery – Toggle anchor tag. To implement a toggle like functionality on a click of a button, you can do like below. Note, this uses jQuery. jQuery disable button: This article explains how to make any button tag, anchor tag or div tag disable or non-clickable.There are many cases when based on some condition and after performing some action, we need to make HTML button or input tag as disable or to remove it from the web page.

I have used button along with the style attributes

background-color: Transparent;
    border: none;

instead of anchor tag to fix the issue. The style attributes helped to remove the grayed out area of the original html button and to keep my own image for the button.

example code is given below:

<button> id="moreButton" class="contactButtonSmall" style="position:absolute; left:225px; top:165px;  FONT-WEIGHT:normal; FONT-SIZE:11pt; background-color: Transparent;border: none;" onclick="doSomething();">More</button>

In CSS file:

.contactButtonSmall {
    position:relative;
    display: block; /* 'convert' <a> to <div> */
    width: 60px;
    max-height: 20px;
    padding-top: 2px;
    padding-bottom: 2px;
    background-position: center top;
    background-repeat: no-repeat;
    background-image: url(../contactImages/blankSmallButton.gif);
    text-decoration: none;
    text-align: center;
    cursor:pointer;
    background-color: Transparent;
    border: none;
}

How to enable or disable an anchor tag with JavaScript/jQuery , When the Button is clicked, the EnableDisableLinks JavaScript function is executed. In order to disable a HTML Anchor Link (HyperLink), the value of its HREF  HTML disabled attribute does not work for HTML anchor tags (HyperLink) and they are still clickable. Enable Disable Anchor Tags (Links) using JavaScript HTML consists of three HTML Anchor Links (HyperLink) and a button. When the button is clicked, EnableDisableLinks JavaScript function is executed.

You can use a mixture of CSS and JS to accomplish this:

HTML:

<a href="/" id="myLink">
    click me!
</a>

CSS:

#myLink {
    background: red
}

a#myLink.disabledLink {
    background: grey;
    cursor: not-allowed;
}

JS:

document.getElementById("myLink").onclick = function(e)
{
    e.preventDefault();
    this.className += " disabledLink";
}

jsfiddle here

this on click prevents the default action of the anchor tag and assigns it a class. The class has css that makes the cursor show the now-allowed icon as well as changing background colour to grey.

Enable Disable Anchor Tags (Links) using JavaScript and jQuery, dev docs, the disabled property is not compatible with the anchor tag. Adding the bootstrap .disabled class however will disable the button  You cant disable an anchor tag. Instead you could something like this: [code]<a href="javascript:void(0)" /> [/code]This will prevent the link from redirecting on

HTML disabled Attribute, Since the designers of HTML saw fit to give <button> a disabled attribute that You could remove the href and store its value into a data-* attribute, but it's a The act of following a link is always supposed to be 'safe' - it won't  Enable Disable Anchor Tags (Links) using JavaScript The following HTML Markup consists of three HTML Anchor Links (HyperLink) and a Button. When the Button is clicked, the EnableDisableLinks JavaScript function is executed.

Replace 'disabled' attributes from HTML anchor tags · Issue #7943 , The disabled attribute is allowed only for form controls. Using it with an anchor tag (an <a> link) will have no effect. The element will, however,  Disable onclick event of a link button or an anchor tag using javascript First of all you should know that asp link button is rendered as anchor tag. So, if you want to disable onclick event of a link button or an anchor tag using javascript, you should set the onclick event as follows:

Adding a [disabled] attribute to <a>s - HTML, HTML consists of three HTML Anchor Links (HyperLink) and a button. In order to disable a HTML Anchor Link (HyperLink), the value of its  All IEs has its own proprietary logic of disabling anchor, buttons and even other elements by default.This workaround needed for non-IE browsers. – vitrilo May 18 '16 at 11:16 3 +1.

Comments
  • firstly) inline css/js is bad practice that may lead to hard-to maintain code and other annoyances down the line. Secondly) why not disable the tag and just add css to grey it out?
  • @Turnip Sorry I didn't see the code
  • You can not disable an <a> tag in this way. The disabled attribute is for the <button> element, which you are not using.
  • just following up- has any solution been found? :)
  • @treyBake I have added the answer. Please take a look.
  • The a tag has no disabled attribute so this would not work. jsfiddle.net/g27cLwd1/1
  • That's not really what they're asking, they want to know how to style it so it doesn't look like an anchor.
  • to downvoted - lemme know what's wrong so I can improve my answer :)