Answers for "js get element by id click"

10

get id of clicked element javascript

<button id="3" onClick="reply_click(this.id)">B3</button>
    
<script type="text/javascript">
  function reply_click(clicked_id)
  {
      alert(clicked_id);
  }
</script>
Posted by: Guest on March-26-2020
0

javascript click button by id

var button = document.getElementById("button");
button.click();
Posted by: Guest on May-20-2020
0

get element by click

document.addEventListener('click', function(e) {
    e = e || window.event;
    var target = e.target || e.srcElement,
        text = target.textContent || target.innerText;   
}, false);
Posted by: Guest on April-08-2021
0

get element by click

window.onclick = e => {
    console.log(e.target.innerText);
}
Posted by: Guest on April-08-2021
0

get element by click

window.onclick = e => {
    console.log(e.target);  // to get the element
    console.log(e.target.tagName);  // to get the element tag name alone
}
Posted by: Guest on April-08-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language