Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

170
Vistas
How can I remove href attribute from anchor tag using JavaScript?

I want to remove or disable anchor tag attribute which comes under <div class="removetag"> class from JavaScript without giving specific id to one anchor tag we can use div class for that.

Please help me how to I can do this thing.

My code

<div class="removetag">
  <a href="google.com"> google </a>
</div>

<div class="notremove">
  <a href="google.com"> google </a>
</div>
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

I think this is what you need:

document.querySelector('.removetag a').removeAttribute('href')
about 4 years ago · Juan Pablo Isaza Denunciar

0

Since you've tagged the question with jQuery, you can solve your problem this way:

$(".removetag a").removeAttr("href");

Demo

$(".removetag a").removeAttr("href");
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="removetag">
  <a href="google.com"> google </a>
</div>

<div class="notremove">
  <a href="google.com"> google </a>
</div>

about 4 years ago · Juan Pablo Isaza Denunciar

0

to remove a an attribute you should use removeAttribute('attributeName'): removeAttribute('href')

to select a class use querySelector. However this will only return the first element with this class. To get all elements with this class you need to use querySelectorAll and use forEach to give a command to all of those elements.

var removetag = document.querySelectorAll('.removetag a');
removetag.forEach(el => el.removeAttribute('href'));
<div class="removetag">
  <a href="google.com"> google </a>
</div>

<div class="notremove">
  <a href="google.com"> google </a>
</div>

<div class="removetag">
  <a href="google.com"> google </a>
</div>

<div class="notremove">
  <a href="google.com"> google </a>
</div>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda