Attach a click event to a <p> element with on() - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:on

Description

Attach a click event to a <p> element with on()

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("p").on("click", function(){
        $(this).hide();/*from   w  w w. j a v  a  2s  .  c om*/
    });
});
</script>
</head>
<body>

<p>If you click on me, I will disappear.</p>
<p>Click me away!</p>
<p>Click me too!</p>

</body>
</html>

Related Tutorials