jQuery‎ > ‎


jQuery lets us pass data to events.  This lets us close context.  Consider the following code:
        <title>jQ - Context</title>
        <script type="text/javascript"
        <script type="text/javascript">
            myObj = {
                value:  2,
                value2: 3
                jQuery("#closedContext").click({value: myObj.value, obj: myObj}, function(event){
                    event.data.value      *= 2;

                    //You can use this same logic to pass 'this' into a jQuery context scope.
                    event.data.obj.value2 *= 3;
                    //Every time #closedContext is clicked, myObj.value2 gets multiplied by 3.
                myObj.value = 4;
    <body id="body" onload="">
    <button id="looseContext">Value of 4</button>
    <button id="closedContext">Multiples of 2</button>
    <button id="looseContext2"> Changing Value with multiples clicks </button>