skip to Main Content

I want my code to only peform the onlick() before a button is pressed. How can i remove the onclick() so that they dont pass anything

(remove onclick())

<button class="testclass" id="testid" onclick="test()">finish setup</button> (button to execute the removal of onclick())

I tried with

document.getElementById("boardsection1").removeAttribute("onclick") 

however it did not affect anything

3

Answers


  1. Assign null to the onclick property:

    document.getElementById("boardsection1").onclick = null;l
    
    Login or Signup to reply.
  2. <button class="testclass" id="testid" onclick="test()">finish setup</button>
    <button onclick="removeOnClick()">Remove onclick</button>
    
    <script>
      function removeOnClick() {
        var button = document.getElementById("testid");
        button.removeAttribute("onclick");
      }
    </script>
    Login or Signup to reply.
  3. <button class="testclass" id="testid" onclick="test()">finish setup</button>
    
    <script>
      let button = document.getElementById("testid");
      button.removeAttribute("onclick");
    </script>
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search