In: Computer Science
Write a jQuery click event handler for all tags within
elements. In the handler, output the src attribute of the image to the console.
Jquery Click event handler sample code:
1.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>click demo</title>
<style>
p {
color: red;
margin: 5px;
cursor: pointer;
}
p:hover {
background: yellow;
}
</style>
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
</head>
<body>
<p>First Paragraph</p>
<p>Second Paragraph</p>
<p>Yet one more Paragraph</p>
<script>
$( "p" ).click(function() {
$( this ).slideUp();
});
</script>
</body>
</html>
2.
$( "#target" ).click(function() {
alert( "Handler for .click() called." );
});
3.
<div id="target">
Click here
</div>
<div id="other">
Trigger the handler
</div>
4.
$("p").dblclick(function(){
$(this).hide();
});
5.
$("#p1").mouseenter(function(){
alert("You entered p1!");
});
6.
$("#p1").mouseleave(function(){
alert("You entered p1!");
});
7.
$("#p1").hover(function(){
alert("You entered p1!");
},
function(){
alert("Bye! You now leave p1!");
});