Same jQuery code returns two different results – Submit Button Text
<p>I have two <code>jQuery</code> codes - <a href="http://jsfiddle.net/Lijo/CXGX7/7/" rel="nofollow">http://jsfiddle.net/Lijo/CXGX7/7/</a> and <a href="http://jsfiddle.net/Lijo/CXGX7/8/" rel="nofollow">http://jsfiddle.net/Lijo/CXGX7/8/</a> . The first code returns <code>undefined</code> whereas the second code returns text of button. </p>

<p><strong>QUESTIONS</strong></p>

<ol>
<li>What is the reason for this difference in result?</li>
<li>Why is the first code not returning expected text of button?</li>
</ol>

<p>Note: I verified that both are using same <code>version</code> of jQuery (by an alert of jQuery)</p>

<pre><code>alert($.fn.jquery);
</code></pre>

<p><strong>CODE</strong></p>

<pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;&lt;title&gt;

&lt;/title&gt;
&lt;script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.8.1.js"&gt;&lt;/script&gt;

&lt;script type="text/javascript"&gt;

    alert($('.myButton').attr("value"));

&lt;/script&gt;

&lt;/head&gt;
&lt;body&gt;

&lt;form method="post" action="Test.aspx" id="form1"&gt;
&lt;div class="aspNetHidden"&gt;
&lt;input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE0MDM4MzYxMjNkZMycQvsYQ+GPFsQHoQ8j/8vEo2vQbqkhfgPc60kxXaQO" /&gt;
&lt;/div&gt;

&lt;div class="aspNetHidden"&gt;

&lt;input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwKqxqqrCgLi/JazDQKM54rGBqgaroRQTXJkD1LyUlVxAmLRCNfTGVe73swQBMemBtvN" /&gt;
&lt;/div&gt;
&lt;div&gt;

    &lt;input name="txtEmpName" type="text" id="txtEmpName" /&gt;

    &lt;input type="submit" name="Button1" value="Submit" id="Button1" class="myButton" /&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>REFERENCES</p>

<ol>
<li><a href="http://stackoverflow.com/questions/487056/retrieve-button-value-with-jquery">Retrieve Button value with jQuery</a></li>
<li><a href="http://stackoverflow.com/questions/3240296/how-to-determine-and-print-jquery-version">How to determine and print jQuery version?</a></li>
</ol>
