Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

169
Views
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 answers
Answer question

0

I think this is what you need:

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

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!