jQuery selectors & events (click)
Sat Nov 16 2024 02:00:16 GMT+0000 (Coordinated Universal Time)
Saved by
@signup1
//index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery Toggle Events</title>
<link rel="stylesheet" href="styles.css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<button id="toggleButton">Show/Hide Content</button>
<div id="toggleContent" class="hidden">
<p>This content can be toggled on/off by clicking the button.</p>
</div>
<script src="script.js"></script>
</body>
</html>
//styles.css
body {
font-family: Arial, sans-serif;
text-align: center;
padding: 50px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}
#toggleContent {
margin-top: 20px;
padding: 20px;
background-color: lightgray;
border-radius: 5px;
}
.hidden {
display: none;
}
//script.js
$(document).ready(function() {
// Toggle content visibility when button is clicked
$('#toggleButton').click(function() {
$('#toggleContent').toggleClass('hidden');
});
});
content_copyCOPY
Comments