Same jQuery code returns two different results – Submit Button Text
Posted
by
Lijo
on Stack Overflow
See other posts from Stack Overflow
or by Lijo
Published on 2012-12-11T16:57:36Z
Indexed on
2012/12/11
17:03 UTC
Read the original article
Hit count: 278
jQuery
I have two jQuery
codes - http://jsfiddle.net/Lijo/CXGX7/7/ and http://jsfiddle.net/Lijo/CXGX7/8/ . The first code returns undefined
whereas the second code returns text of button.
QUESTIONS
- What is the reason for this difference in result?
- Why is the first code not returning expected text of button?
Note: I verified that both are using same version
of jQuery (by an alert of jQuery)
alert($.fn.jquery);
CODE
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
</title>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.8.1.js"></script>
<script type="text/javascript">
alert($('.myButton').attr("value"));
</script>
</head>
<body>
<form method="post" action="Test.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE0MDM4MzYxMjNkZMycQvsYQ+GPFsQHoQ8j/8vEo2vQbqkhfgPc60kxXaQO" />
</div>
<div class="aspNetHidden">
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwKqxqqrCgLi/JazDQKM54rGBqgaroRQTXJkD1LyUlVxAmLRCNfTGVe73swQBMemBtvN" />
</div>
<div>
<input name="txtEmpName" type="text" id="txtEmpName" />
<input type="submit" name="Button1" value="Submit" id="Button1" class="myButton" />
</div>
</form>
</body>
</html>
REFERENCES
© Stack Overflow or respective owner