Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8886663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:36:46+00:00 2026-06-14T21:36:46+00:00

Possible Duplicate: Remove all elements with a certain class with JavaScript As title, google

  • 0

Possible Duplicate:
Remove all elements with a certain class with JavaScript

As title, google search gives me all jquery results. Is there a method that does this? ex.

<div id="container">
   <div class="dontdelete">...</div>
   <div class="deleteme>...</div>
   <div class="dontdelete">...</div>
   <div class="deleteme>...</div>
   <div class="dontdelete">...</div>
   <div class="deleteme>...</div>
</div>

Is there a method in pure javascript to delete all child with “deleteme” class? Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:36:47+00:00Added an answer on June 14, 2026 at 9:36 pm

    Since element.getElementsByClassName returns a live node list, you need to loop through the list in a certain way (since removing them from the DOM removes them from the list as well). Try something like this:

    var container = document.getElementById("container");
    var elements = container.getElementsByClassName("deleteme");
    
    while (elements[0]) {
        elements[0].parentNode.removeChild(elements[0]);
    }
    

    DEMO: http://jsfiddle.net/sR2zT/1/

    Or you could use something like element.querySelectorAll to select the elements, where you can do things like this:

    document.querySelectorAll("#container .deleteme")
    // or
    document.getElementById("container").querySelectorAll(".deleteme")
    

    In this scenario, you don’t need to do special looping, because querySelectorAll doesn’t contain a live node list.

    References:

    • getElementsByClassName() – https://developer.mozilla.org/en-US/docs/Web/API/Element/getElementsByClassName
    • querySelectorAll() – https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelectorAll
    • removeChild() – https://developer.mozilla.org/en-US/docs/Web/API/Node/removeChild
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: JQuery, is there a way to select all elements on the page
Possible Duplicate: Php: remove all tags, but “a href” in a text Is there
Possible Duplicate: How to remove all CSS classes using jQuery? I have the following:
Possible Duplicate: Remove all multiple spaces in Javascript and replace with single space How
Possible Duplicate: Google Maps API v3: How to remove all markers? I'm trying to
Possible Duplicate: Remove elements from array? how would I remove all array elements but
Possible Duplicate: how to empty an array in JavaScript How to remove all items
Possible Duplicate: Is there a PHP function to remove any/all key/value pairs that have
Possible Duplicate: php regexp: remove all attributes from an html tag $input = '<div
Possible Duplicate: How to remove border around text/input boxes? (Chrome) Is there a way

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.