[jQuery] $(form.elements) fails in Safari
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.2963" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=gmail_quote>On 10/31/06, <B class=gmail_sendername>Pascal</B>
<<A href="mailto:pascal@pascal.com">pascal@pascal.com</A>>
wrote:</SPAN></DIV>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">
<DIV>I'm trying to do some jQuery manipulations on a form. A reference
to<BR>the form is in the variable 'theForm'. the following generates
an<BR>error in Safari:<BR><BR>alert( $(theForm.elements) );<BR><BR>the error
generated is: <BR><BR>Value undefined (result of expression f.apply) is not
object.<BR><A
href="http://mydomain.com/lib/js/jquery/jquery.js">http://mydomain.com/lib/js/jquery/jquery.js</A> Line
3578<BR><BR>I'm using revision 443 of jQuery. <BR><BR>Anyone have an idea what
might be causing this? I have a feeling it<BR>might be related to an earlier
discussion about passing/manipulating<BR>nodelists in Safari. If so, was there
a resolution to that problem<BR>that might apply here?<SPAN
class=454002613-02112006> </SPAN></DIV></BLOCKQUOTE>
<DIV><SPAN class=454002613-02112006></SPAN> </DIV>
<DIV><SPAN class=454002613-02112006><FONT face=Arial color=#0000ff size=2>I
missed your earlier post, Pascal. Yes, I think the problem is in jQuery.clean()
where it checks the incoming argument for the .nodeType property. We are trying
to separate DOM elements with a length property (which we don't want to
enumerate) from DOM nodelist collections (which we do). </FONT></SPAN></DIV>
<DIV><SPAN class=454002613-02112006><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=454002613-02112006><FONT face=Arial color=#0000ff size=2>It
might be possible to find some other property that Safari wouldn't find
crashingly offensive? Nodelists only have two documented properties,
.length and .item. It still seems easier to look for some "not a nodelist"
indicator. </FONT></SPAN></DIV>
<DIV><SPAN class=454002613-02112006><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=454002613-02112006><FONT face=Arial color=#0000ff
size=2>Something just occurred to me, maybe Safari is upset trying to convert
the nodeType to a boolean with the "!" operator. It's saying the value is
undefined, and that is correct, so maybe we can check directly for
undefined. Perhaps you could try this instead?</FONT></SPAN></DIV>
<DIV><SPAN class=454002613-02112006><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=454002613-02112006><FONT face=Arial color=#0000ff
size=2>Change</FONT></SPAN></DIV>
<DIV><SPAN class=454002613-02112006><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=454002613-02112006><FONT face=Arial color=#0000ff
size=2> else if ( arg.length != undefined &&
!arg.nodeType ) // Handles Array, jQuery, DOM NodeList
collections<BR></FONT></SPAN></DIV>
<DIV><SPAN class=454002613-02112006><FONT face=Arial color=#0000ff
size=2>to</FONT></SPAN></DIV>
<DIV><SPAN class=454002613-02112006><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=454002613-02112006><FONT face=Arial color=#0000ff
size=2> else if ( arg.length != undefined &&
arg.nodeType == undefined ) // Handles Array, jQuery, DOM NodeList
collections<BR></FONT></SPAN></DIV>
<DIV><SPAN class=454002613-02112006><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=454002613-02112006><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV></BODY></HTML>
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/