document.getElementById('button').onclick = function() {
alert("button was clicked");
};
// Create variable for what you are trying to click
let button = document.querySelector("#IDofItem");
// Click the button
if (button) {
button.click();
}
else {
console.log("Error");
}
window.onload = function() {
var userImage = document.getElementById('imageOtherUser');
var hangoutButton = document.getElementById("hangoutButtonId");
userImage.onclick = function() {
hangoutButton.click(); // this will trigger the click event
};
};
document.addEventListener('click', function(e) {
e = e || window.event;
var target = e.target || e.srcElement,
text = target.textContent || target.innerText;
}, false);
<element onclick="functionToExecute()">Click</element>
/*
The onclick event generally occurs when the user clicks on an element.
It allows the programmer to execute a JavaScript's function when an element
gets clicked
*/
<!DOCTYPE html>
<html>
<head>
<script>
function fun() {
alert("Welcome to the javaTpoint.com");
}
</script>
</head>
<body>
<h3> This is an example of using onclick attribute in HTML. </h3>
<p> Click the following button to see the effect. </p>
<button onclick = "fun()">Click me</button>
</body>
</html>
$('.btn').click(function() {
$('[title=selected]').removeAttr("title");
$(this).attr("title", "selected");
});