if button is pressed javascript code example
Example 1: how to check if you click something in javascript
const element = document.getElementById('profile_title')
element.addEventListener("click", () => {
alert('hello');
});
Example 2: how to check if the button is clicked or not in javascript
if(document.getElementbyId("id do item").clicked == true){
window.alert("ok")
}
Example 3: if button is pressed js
<button>A</button>
<button>B</button>
<button>C</button>
<script>
document.body.addEventListener("click", event => {
if (event.target.nodeName == "BUTTON") {
console.log("Clicked", event.target.textContent);
}
});
</script>