onclick event not working in JavaScript

前端 未结 9 1747
深忆病人
深忆病人 2020-12-02 19:36

I have some JavaScript code in an HTML page with a button. I have a function called \'click()\' that handles the onClick event of the button. The code for the button is as f

相关标签:
9条回答
  • 2020-12-02 20:33

    Today this also happened to me. The function name maybe conflicts with keywords. My case is scrape(). I change the function name, everything works fine.

    0 讨论(0)
  • 2020-12-02 20:35

    Try fixing the capitalization. onclick instead of onClick

    Reference: Mozilla Developer Docs

    0 讨论(0)
  • 2020-12-02 20:35
    <script>
    //$(document).ready(function () {
    function showcontent() {
            document.getElementById("demo22").innerHTML = "Hello World";
    }
    //});// end of ready function
    </script>
    

    I had the same problem where onclick function calls would not work. I had included the function inside the usual "$(document).ready(function(){});" block used to wrap jquery scripts. Commenting this block out solved the problem.

    0 讨论(0)
提交回复
热议问题