Welcome to our comprehensive guide on jQuery Controlgroup Widget! This tutorial is designed for both beginners and intermediate learners who want to explore this powerful jQuery plugin.
The Controlgroup Widget is a jQuery plugin that helps to create a group of radio buttons or checkboxes, which behave like a single select element. It provides a clean, unified look and makes user interaction more intuitive.
First, let's include the jQuery and Controlgroup plugin in our HTML file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-controlgroup/1.2.0/jquery.controlgroup.min.js"></script>
</head>
<body>
<!-- Controlgroup Widget Example -->
</body>
</html>Now, let's create a simple Controlgroup with radio buttons:
<div class="control-group" data-controlgroup>
<input type="radio" id="option1" name="group1" value="Option 1" />
<label for="option1">Option 1</label>
<input type="radio" id="option2" name="group1" value="Option 2" />
<label for="option2">Option 2</label>
</div>Don't forget to add some CSS to style our Controlgroup:
.control-group {
display: flex;
align-items: center;
}
.control-group label {
margin-left: 10px;
}Finally, let's activate the Controlgroup Widget by adding the following jQuery code:
$(document).ready(function() {
$('.control-group').controlgroup();
});Now, when you run your HTML file, you should see a functioning Controlgroup with radio buttons!
What is the main purpose of the Controlgroup Widget?
We hope you enjoyed learning about the jQuery Controlgroup Widget! Stay tuned for more advanced examples and tutorials on CodeYourCraft. Happy coding! 🎉