Trying to log to console with onclick event [closed]

本秂侑毒 提交于 2019-12-03 22:01:11

For an inline click event, this is what you need:

<div onclick='console.log("Hello")'>1</div>

http://jsfiddle.net/vu3xo3am/2/

Or,

If you want to do this unobtrusively, this would be how you could do it:

<div id="test">1</div>

var test = document.getElementById('test');
test.onclick = function() {
    console.log('Hello');
}

http://jsfiddle.net/vu3xo3am/3/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!