About Lesson
Collapsible FAQ Section using JQuery
JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FAQ Section</title>
<style>
.faq {
margin-bottom: 10px;
}
.answer {
display: none;
padding: 10px;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div class="faq">
<h3 class="question">What is jQuery?</h3>
<p class="answer">jQuery is a JavaScript library for simplifying DOM manipulation.</p>
</div>
<div class="faq">
<h3 class="question">Why use jQuery?</h3>
<p class="answer">It makes JavaScript coding easier and faster.</p>
</div>
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script>
$(document).ready(function () {
$(".question").click(function () {
$(this).next(".answer").slideToggle();
});
});
</script>
</body>
</html>