We Lab9
We Lab9
UI22EC85
Q.1 Create the webpage to demonstrate the following effects on the content or
HTML elements with the help of jQuery operations. (Note: This can be
triggered by the user clicking some element or can be fired by some other
event.)
b. Sliding and Fading Elements in and out of View (Functions for reference: slideUp,
slideDown, slideToggle, fadeIn, fadeout, fadeTo).
c. Show images one after the other on hover (Consider several images to be
displayed and display them one by one. The first image is displayed, and when you
hover over it, it should fade out, and another image fades in. Then the second image
fades out on hover, and the third image fades in, and so on. After the last image, the
first image reappears).
CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
.container {
margin: 20px;
}
.box {
width: 200px;
height: 100px;
background-color: lightblue;
margin: 10px;
text-align: center;
line-height: 100px;
cursor: pointer;
.image-container img {
display: none;
width: 200px;
.image-container img:first-child {
display: block;
</style>
</head>
<body>
<div class="container">
<div class="image-container">
</div>
</div>
<script>
$(document).ready(function() {
$("#toggleBtn").click(function() {
$("#toggleBox").toggle(1000);
});
$("#slideToggleBtn").click(function() {
$("#slideBox").slideToggle(1000);
});
$("#fadeToggleBtn").click(function() {
$("#fadeBox").fadeToggle(1000);
});
$(".image-container img").hover(function() {
if (next.length == 0) {
current.fadeOut(500, function() {
next.fadeIn(500);
});
});
});
</script>
</body>
</html>
OUTPUT:
Q.2 Create the webpage to demonstrate the following effects on the HTML
form elements with the help of jQuery operations.
b. Auto tabbing based on character count. (Allow users to enter a 16-digit long serial
number with the help of four input fields. To speed the user along in their data entry,
as each input field is filled up (by 4 characters), automatically focus the next input
field until they are finished typing the number).
CODE:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form Effects Demo</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<h3>Select/Deselect All Checkboxes</h3>
<a href="#" id="toggleCheckboxes">Toggle Checkboxes</a>
<br><br>
<input type="checkbox" class="chk"> Checkbox 1
<input type="checkbox" class="chk"> Checkbox 2
<input type="checkbox" class="chk"> Checkbox 3
<input type="checkbox" class="chk"> Checkbox 4
<script>
$(document).ready(function() {
$("#toggleCheckboxes").click(function(event) {
event.preventDefault();
$(".chk").each(function() {
$(this).prop("checked", !$(this).prop("checked"));
});
});
$(".serial").keyup(function() {
if ($(this).val().length == 4) {
$(this).next(".serial").focus();
}
});
});
</script>
</body>
</html>
OUTPUT:
=> After clicking on Toggle Checkboxes:
CONCLUSION: