Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

121
Visualizações
jQuery disable anchor tag bootstrap button onClick

I want to disable my bootstrap button on-click using Javascript, to prevent a double-click in order to avoid DbContext threading issues.

<a type="button" class="btn btn-success" id="BackBtn" asp-area="" asp-controller="PageStuff" asp-action="PageStuff" asp-route-culture="@CultureInfo.CurrentCulture.Name">@_loc[Model.BackButton]</a>

This works as expected and hides the button:

$("#BackBtn").on("click", function () {
    document.getElementById("BackBtn").style.display = "none";
});

This does not disable the button, but works elsewhere in my app for other elements:

$("#BackBtn").on("click", function () {
    document.getElementById("BackBtn").disabled = true;
});

I have also tried using document.getElementById("BackBtn").unbind("click"); as mentioned here.

And this document.getElementById("BackBtn").prop("disabled", true);

and this $("#BackBtn").prop("disabled", "disabled");

and this $('BackBtn').prop("disabled", true);

and this document.getElementById("BackBtn").attr("disabled", "disabled");

and this $("#values:BackBtn").attr("disabled", true);

and this $("#BackBtn").attr("disabled", true);

and this $('BackBtn').attr('readonly', true);

and this [...document.querySelectorAll('BackBtn')].map(e => e.disabled = true);

and various other variations.

Any ideas how I can get the button to disable on click? Does 'disabled' even exist for an anchor tag of type="button" ? Im starting to think there is no such property.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The disabled attribute works only on button, for anchor tag you can use pointer-events: none;

$("#BackBtn").on("click", function() {
  $(this).css('pointer-events', 'none')
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a type="button" class="btn btn-success" id="BackBtn" asp-area="" asp-controller="PageStuff" asp-action="PageStuff" asp-route-culture="@CultureInfo.CurrentCulture.Name" href="#">Dsiable me</a>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda