Skip to content

Instantly share code, notes, and snippets.

@malikkurosaki
Created February 18, 2018 01:18
Show Gist options
  • Save malikkurosaki/4afcd9bc70a25607e774cbe7ea81135a to your computer and use it in GitHub Desktop.
Save malikkurosaki/4afcd9bc70a25607e774cbe7ea81135a to your computer and use it in GitHub Desktop.
get id of element when on click
<div di="container">
<div id="a">this is a</d>
<div id="b">this is b</d>
<div id="c">this is c</d>
<div id="d">this is d</d>
<div id="e">this is e</d>
<div id="f">this is f</d>
<div id="g">this is g</d>
<div id="h">this is h</d>
<div id="i">this is i</d>
<div id="j">this is j</d>
</div>
<div id="result">result here</div>
<script>
document.body.onclick = function(ev){
document.getElementById("result").innerHTML = ev.target.id;
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment