Trigger a button click from a non-button element

前端 未结 6 1915
遥遥无期
遥遥无期 2020-12-05 19:32

How would you trigger a click event from an element that supposedly does not have native clickable behaviours?

For example, I know that you could simply just use the

6条回答
  •  [愿得一人]
    2020-12-05 20:01

    Try doing something like the following:

    var my_div = document.getElementById('x');
    my_div.onclick = function() {
       alert('hello world');
    }
    

提交回复
热议问题