Skip to content

Instantly share code, notes, and snippets.

@courtney-scripted
Last active March 6, 2018 23:04
Show Gist options
  • Save courtney-scripted/f960126b01a4255deed2e6a79c60d286 to your computer and use it in GitHub Desktop.
Save courtney-scripted/f960126b01a4255deed2e6a79c60d286 to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=f960126b01a4255deed2e6a79c60d286

There are four rectangles on the page. Please write event handlers to change the content and style based on the user's actions.

1) The top left rectangle

Write an event handler to change the text to "Thank you for clicking on me!" and the background color to green when the user clicks on the rectangle.

2) The top right rectangle

Write an event handler to change the text to "Thank you for double-clicking on me!" and the background color to blue when the user double-clicks on the rectangle.

3) The bottom left rectangle

Write an event handler to change the text to "Thank you for hovering on me!" and the background color to yellow when the user hovers their mouse over the box.

4) The bottom right rectangle

Write an event handler to change the text to "Thank you for visiting!" and the background color to white when the user's mouse enters the rectangle, and then to "Come again soon!" and the background color to red when the user's mouse leaves the rectangle.

Hint: You need 2 event handlers for this rectangle

<!DOCTYPE html>
<html>
<head>
<title>jQuery Events with description</title>
</head>
<body>
<div class="parent">
<div class="top-left box">Click on me</div>
<div class="top-right box">Double click on me</div>
</div>
<div class="parent">
<div class="bottom-left box">Type something</div>
<div class="bottom-right box">Put your mouse on me!</div>
</div>
</body>
</html>
{"enabledLibraries":["jquery"],"hiddenUIComponents":["console","editor.css"]}
$(".top-left").click(function(){
$(".top-left").text("Thank you for clicking on me!");
$(".top-left").css("background-color", "green");
});
$(".top-right").dblclick(function(){
$(".top-right").text("Thank you for double-clicking on me!");
$(".top-right").css("background-color", "blue");
});
$(".bottom-left").hover(function(){
$(".bottom-left").text("Thank you for hovering on me");
$(".bottom-left").css("background-color", "yellow");
});
$(".bottom-right").mouseenter(function(){
$(".bottom-right").text("Thank you for stopping by!");
$(".bottom-right").css("background-color", "white");
});
$(".bottom-right").mouseleave(function(){
$(".bottom-right").text("Come again soon!");
$(".bottom-right").css("background-color", "red");
});
.box {
width: 220px;
height:220px;
border: solid 2px grey;
background-color: lightgrey;
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 20px;
}
.parent {
display: flex;
justify-content: space-around;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment