JavaScript - jQuery toggle option
<p>I have a script to execute some tasks based on an option variable. Option has a default value 1. The value can be toggled by clicking some links. Then a set of operations are set, for that operations to execute. The sample layout will be like;</p>

<p>HTML</p>

<pre><code>&lt;a id="opt1"&gt;1&lt;/a&gt;&lt;br&gt;&lt;a id="opt2"&gt;2&lt;/a&gt;&lt;br&gt;&lt;a id="opt3"&gt;3&lt;/a&gt;&lt;br&gt;
&lt;div id="mydiv"&gt;option1&lt;/div&gt;
</code></pre>

<p>JS</p>

<pre><code>var opt=1;
$('#opt1').click(function() {
    opt=1;
});
$('#opt2').click(function() {
    opt=2;
});
$('#opt3').click(function() {
    opt=3;
});
if(opt == 1){
    $('#mydiv').text("option1");
}else if(opt == 2){
    $('#mydiv').text("option2");
}else{
    $('#mydiv').text("option3");
}
</code></pre>

<p>JS is wrapped inside document ready function. The sample is meant to change text according to option variable. Sorry that the tasks cannot be nested inside <code>.click(function()</code> and are purely depend on option value. How can I achieve this?</p>

<p>here is the fiddle <a href="http://jsfiddle.net/Naw3y/" rel="nofollow">http://jsfiddle.net/Naw3y/</a></p>
