skip to Main Content

can someone please tell me how to remove div element using javascript.
I’m on a Shopify theme edit.

I need to this to be or

2

Answers


  1. First, get the div that you need to remove.

    and then remove the div from its parent.

    var element = document.getElementById("childDiv");
    element.parentNode.removeChild(element);
    
    Login or Signup to reply.
  2. Here is some example hope this will help you!

    var btn = document.getElementById('btn');
    btn.onclick = function () {
        document.getElementById('did').remove();
        this.remove();
    };
    <div id='did'>
    <p id='pid'>Hello World</p>
    <input id='btn' type="submit" value='REMOVE THAT!!!'/>
    </div>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search