Program9
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery Combined Example</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
text-align: center;
}
p, ul {
margin: 20px 0;
}
#box {
width: 100px;
height: 100px;
background-color: #2196f3;
margin: 20px auto;
}
button {
padding: 10px 15px;
margin: 10px 5px;
cursor: pointer;
background-color: #4caf50;
color: white;
border: none;
border-radius: 5px;
}
button:hover {
background-color: #388e3c;
}
</style>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<h1>jQuery Combined Example</h1>
<!-- Content to append to -->
<p id="paragraph">This is a paragraph.</p>
<ul id="list">
<li>Item 1</li>
<li>Item 2</li>
</ul>
<!-- Animated div -->
<div id="box"></div>
<!-- Buttons -->
<button id="append-btn">Append Content</button>
<button id="animate-btn">Animate Box</button>
<button id="changeColor-btn">Animate and Change Color</button>
<script>
$(document).ready(function() {
// Append content to paragraph and list
$('#append-btn').click(function() {
$('#paragraph').append(' Appended text.');
$('#list').append('<li>Appended item</li>');
});
// Animate the div element (expand size)
$('#animate-btn').click(function() {
$('#box').animate({
width: '200px',
height: '200px'
}, 1000);
});
// Animate the div element and change its color
$('#changeColor-btn').click(function() {
$('#box').animate({
width: '150px',
height: '150px'
}, 1000).css('background-color', '#f44336');
});
});
</script>
</body>
</html>
Comments
Post a Comment