Problem with retrieving dynamic value set to an input element in jquery
<p>I have set the value of a hidden input element dynamically on clicking a link. </p>

<pre><code>&lt;input id="flag" type="text" class="hidden"  /&gt; 

$("#changed_link").click(function(){
            $('#flag').val(1);
});
</code></pre>

<p>This link opens a lightbox window. In the lightbox, one of my div, that <code>#section1</code> is hidden. Initially, when I open the lightbox,(by clicking another link), this div is hidden. The second time, when I clicked the second link, i.e, <code>changed_link</code>, I want this <code>#section1</code>  to be shown. </p>

<p>so I tried to set a flag value , while clicking the link, and pass it to the corresponding js file. But when I try to retrieve the value of that hidden input <code>flag</code>, it is undefined in the js file.</p>

<pre><code>var flag=$('#flag').val();
alert(flag); //undefined
</code></pre>

<p>But if the flag value is set initially,  </p>

<pre><code> &lt;input id="flag" type="text" class="hidden" value='1' /&gt; 
</code></pre>

<p>then I get that value in the js file. but then the div <code>section1</code> is always shown. </p>

<p>How can I get the dynamically set value in my js file??</p>
