Hahaha!! Much better!
And there I was, having written a recursive function in order to do it!!
The function worked ok, for the record, but threw an error on
var theparent = theItem.parentNode;
which firebug said had 'no properties'...
Well, I'll look into it should I ever need to step upwards through
ancestors looking for something...
Thanks!
On 3/23/07, Klaus Hartl <[EMAIL PROTECTED]> wrote:
> Dan Eastwell schrieb:
> > I know I can use parents to get the ancestors of my input, but this
> > will get all forms on the page
> >
> > $(#myInput).parents("form");
> >
> > How do I find the one the form is in?
> >
> > var formItsIn = checkAncestors(theSearchBox, "form");
> >
> > function checkAncestors(theItem, requiredAncestor){
> > var theparent = theItem.parentNode.nodeName.toLower();
> > if(theparent == requiredAncestor){
> > return theparent;
> > }else{
> > checkAncestors(theparent, requiredAncestor);
> > }
> > }
> >
> >
> > my code above seems a bit much to me, and it's not jquery!
> >
> > Cheers,
> >
> > Dan.
>
>
> Dan, every form element contained by a form has the form property...:
>
> var formItsIn = theSearchBox.form
>
>
> Much shorter :-)
>
>
> -- Klaus
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>
--
Daniel Eastwell
Portfolio and articles:
http://www.thoughtballoon.co.uk
Blog:
http://www.thoughtballoon.co.uk/blog
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/