I was having this issue with jQuery not being able to find a <form>
element in my HTML for the past day and a half. I ran my HTML through validators multiple times, validated my JS and CSS, and even removed unnecessary JS and CSS files, which is now reduced to this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.8.0r4/build/reset/reset-min.css" />
</head>
<body>
<form>
<input type="textbox" name="action" value="view"></input>
<button>Test</button>
</form>
</body>
</html>
After reducing my HTML to bare bones, I checked if jQuery could simply grab the <form>
element using $('form')
. Well, jQuery returned nothing. It completely crapped out. It returned nothing, not even a jQuery object. So again I continued on with my insanity, validating the HTML, etc. etc., and still nothing!
I rewrote the HTML a second time, but not exactly the same way, and it worked! So I diff'd the two files and started tweaking the original file to incrementally become identical to the new file I had just written. Well it turns out that the value of the name
attribute was the culprit that was screwing everything up! Simply changing the the value to anything other than action
allowed jQuery to finally pick up the <form>
element! Really?! !@#%$!@#!!!
So my questions are: Is action
a keyword in jQuery and how does the value of an attribute screw everything up?
If it is a keyword and you don't feel like explaining why, could you please point me to the documentation on this so I can smack myself in the head after reading it. It still seems rather odd that the value of an attribute would screw things up, but that's probably because I'm ignorant of jQuery's implementation. =)