JavaScript remove button| Example code Simple

Use id in HTML button and removeChild method to remove button Using JavaScript.

Example code remove HTML button Using JavaScript

In the example we have 2 buttons:

  1. First Will remove
  2. Second will remove first button

Action button will call function, where find the element by id then use removeChild method to remove button in JS.

<html>
<body>

    <input type="submit" id="dummy" disabled value="Submit" />
    <input type="button" value="Remove DUMMY" onclick="removeDummy()" />
</body>
<script>
    function removeDummy() {
        var elem = document.getElementById('dummy');
        elem.parentNode.removeChild(elem);
        return false;
    }
</script>
</html>

Output:

JavaScript remove button Using JavaScript HTML

Do comment if you have any doubts and suggestions on this topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.