JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<div class='option'>Option 1</div>
<div class='option'>Option 2</div>
<div class='option'>Option 3</div>
<div class='error-text'></div>
JavaScript
function createClosure(){
var someVar = "Successful variable 'passing'";
// This call will change all the .option objects to say
// "Successful variable 'passing'"
$(".option").each(closure(someVar));
}
function closure(storedVariable){
var someVar = storedVariable;
return function(index, element){
// But we stored it in someVar so we can access it later
$(element).text(someVar);
}
}
// Call it
createClosure();