Sử dụng onclick để thực thi một tập lệnh khi phần tử được nhấp trong HTML.
Ví dụ
Bạn có thể thử chạy mã sau để triển khai onclick thuộc tính -
<!DOCTYPE html>
<html>
<body>
<button onclick = "display()">Click</button>
<p id = "test"></p>
<script>
function display() {
document.getElementById("test").innerHTML = "You clicked the button!";
}
</script>
</body>
</html>