jQuery event.target get the class of the clicked element

Description

jQuery event.target get the class of the clicked element

View in separate window

<!DOCTYPE html>
<html lang="en">
<head>
<title>jQuery Get Class of Clicked Element</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(document).on("click", function(event){
    document.getElementById("demo").innerHTML = 
       event.target.className;/*from ww  w .  java 2  s. c  om*/
})
</script>
</head>
<body>
    <p id="demo"></p>
    <button type="button" class="foo">Button 1</button>
    <input type="button" class="bar" value="Button 2">
    <button type="button" class="baz">Button 3</button>
</body>
</html>



PreviousNext

Related