.clicked javascript code example

Example 1: how to detect a button click in javascript

if(document.getElementById('button').clicked == true)
{
   alert("button was clicked");
}

Example 2: css click event jquery

$('h1').click(function () {
        $(this).css('color', 'blue')
    });

Example 3: javascript click button by id

var button = document.getElementById("button");
button.click();

Example 4: click button javascript

// 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");
}

Example 5: button click function in js

<script>
  $(document).ready(function(){
    $('#MyButton').click(function(){
       CapacityChart();
    });
  });
</script>

<input type="button" value="Capacity Chart" id="MyButton" >

Example 6: element clicked js

document.addEventListener('click', function(e) {
    e = e || window.event;
    var target = e.target || e.srcElement,
        text = target.textContent || target.innerText;   
}, false);

Tags:

Css Example