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 6614599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:21:29+00:00 2026-05-25T20:21:29+00:00

This is either very simple or impossible. I know I can do this: var

  • 0

This is either very simple or impossible.

I know I can do this:

var element = document.getElementById('some_element');
element.parentNode.removeChild(element);

…but it feels messy. Is there a tidier – and universally supported – way to do the same thing?

It’s seems – to me at least – like there should be something like this:

document.getElementById('some_element').remove();

…but that doesn’t work, and searching Google/SO has not yielded any alternative.

I know it doesn’t matter that much, but parentNode.removeChild() just feels hacky/messy/inefficient/bad practice-y.

  • 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-05-25T20:21:30+00:00Added an answer on May 25, 2026 at 8:21 pm

    It can seem a bit messy, but that is the standard way of removing an element from its parent. The DOM element itself can exist on its own, without a parentNode, so it makes sense that the removeChild method is on the parent.

    IMO a generic .remove() method on the DOM node itself might be misleading, after all, we’re not removing the element from existence, just from its parent.

    You can always create your own wrappers for this functionality though. E.g.

    function removeElement(element) {
        element && element.parentNode && element.parentNode.removeChild(element);
    }
    
    // Usage:
    removeElement( document.getElementById('some_element') );
    

    Or, use a DOM library like jQuery which provides a bunch of wrappers for you, e.g. in jQuery:

    $('#some_element').remove();
    

    This edit is in response to your comment, in which you inquired about the possibility to extend native DOM implementation. This is considered a bad practice, so what we do instead, is create our own wrappers to contain the elements and then we create whatever methods we want. E.g.

    function CoolElement(element) {
        this.element = element;
    }
    
    CoolElement.prototype = {
        redify: function() {
            this.element.style.color = 'red';
        },
        remove: function() {
            if (this.element.parentNode) {
                this.element.parentNode.removeChild(this.element);
            }
        }
    };
    
    // Usage:
    
    var myElement = new CoolElement( document.getElementById('some_element') );
    
    myElement.redify();
    myElement.remove();
    

    This is, in essence, what jQuery does, although it’s a little more advanced because it wraps collections of DOM nodes instead of just an individual element like above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a very simple setup, I can't believe but I didn't find anybody
Anyone know of a control for asp.net that can achieve this either server or
This seems like a very simple problem, but I cannot get a scrollbox to
Im sure this is a very simple and easy to answer question but I've
I've been stuck on this likely very simple problem, but haven't gotten anywhere with
All, This question probably has a very simple answer - something I'm overlooking. But
There might be some very simple answer to this, but i am really stuck
I guess this is a quite simple (read: very simple) question, but I have
I feel like this must be very simple, but for some reason I am
This could either be very simple or quite complex I'm not sure at this

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.