Create Engaging Fill-in-the-Blank Quizzes with fillInTheBlank.js
File Size: | 5.45 KB |
---|---|
Views Total: | 32 |
Last Update: | |
Publish Date: | |
Official Website: | Go to website |
License: | MIT |
fillInTheBlank.js is a lightweight jQuery plugin that lets you create interactive fill-in-the-blank questions on web pages.
The plugin can be helpful in creating fill-in-the-blank exercises for educational websites, quizzes, or any scenario requiring interactive content. It enhances user engagement by turning passive reading into an active learning experience.
Under the hood, fillInTheBlank.js transforms text enclosed in custom delimiters into dynamic, editable elements where users can input their answers. If the correct answer is entered, it’s displayed on the page; otherwise, a custom error event is fired.
How to use it:
1. Include the jQuery library (the slim build is recommended) and the fillInTheBlank.js script in your HTML file.
<script src="/path/to/cdn/jquery.slim.min.js"></script> <script src="/path/to/dist/fillInTheBlank.js"></script>
2. Create your fill-in-the-blank questions within your HTML content. Wrap the correct answer with the default delimiter character "^". Note that you can customize this delimiter later. The <pre>
element used in the example can be replaced with any other suitable HTML element.
<pre> jQueryScript.Net is a ^JavaScript^ website. </pre>
3. Call the fillInTheBlank()
function on the element containing your questions.
$(function(){ $("pre").fillInTheBlank(); });
4. You can then customize the plugin's behavior using the following options:
$("pre").fillInTheBlank({ // Delimiter character delimiter: "^", // Event that triggers the answer check event: "change", // event handlers correct: function() { alert("Correct!"); }, wrong: function() { alert("Sorry, that's incorrect."); } });
How it works:
The plugin uses jQuery to transform the content. It identifies text within specified delimiters and replaces it with input fields. The original text becomes the expected answer, stored as a data attribute.
The plugin sets up event listeners for user input. When triggered, it compares the input against the stored answer. Correct answers trigger the 'correct' function, while incorrect ones trigger the 'wrong' function.
The code uses regular expressions to find delimited text and replace it with span elements. These spans are then converted to input fields, preserving the original text's width for a seamless appearance.
Event handling is set up to check answers and trigger appropriate responses. This creates an interactive, responsive experience for users.
This awesome jQuery plugin is developed by goonruntongue. For more Advanced Usages, please check the demo page or visit the official website.
- Prev: Enhance Text with Custom Acronym Styling - jQuery AcronymJS
- Next: None