I don't know if you've found these yet, but here are two great sources
of information - reading the examples in the api browser will really
help you get your head around the jquery methodology.  I'm from a DOM
background too, and this is how I got up to speed

http://jquery.bassistance.de/api-browser/

http://docs.jquery.com/DOM/Traversing/Selectors

In particular, look at the bottom of the selectors page to see about
accessing form element types, and use Andy's suggestion if you want to
use name attributes.  In general, classes are faster for grabbing
multiple nodes, and ID's are fastest for single nodes.

If you're wanting to kill all siblings after a specific node you can
probably use :gt and :lt in a children set.  Something like $
('div').children(':gt(4)').remove();  I haven't ever needed to do this
so it's untested, but in theory it should work.

:gt(4) Selects all matched elements whose index is greater than N.
:lt(4) Selects all matched elements whose index is less than N.



On May 23, 9:35 am, "Glen Lipka" <[EMAIL PROTECTED]> wrote:
> re: the second part.
> Do you mean something like:
> $("input").next().remove();
> or
> $("input").siblings("div.error").remove();
>
> You can see different ways of achieving the same goal depending on your
> structure and circumstances.
>
> Glen
>
> On 5/23/07, cliff <[EMAIL PROTECTED]> wrote:
>
>
>
> > I am new to jQuery and have several questions:
>
> > 1. To access a form element, I use: document.forms[frmname]
> > [elementname]
> >           What is the jQuery equivalent?
> >           Will there be any significant speed difference between the
> > old and jQuery way?
>
> > 2. This is basically the same as #1. I am getting the hang of
> > accessing elements by id using $("#elementid"), but how do I access
> > form elements by name so I can avoid using ids.
>
> > 3. I want to strip error messages after an input element --
> > essentially just stripping DOM siblings after the input element. See
> > function below:
>
> > function removeNextSiblings(elementid) {
> >         var element = document.getElementById(elementid);
> >         var parent = element.parentNode;
> >         while (parent.lastChild) {
> >                 if (parent.lastChild == element)
> >                         break;
> >         parent.removeChild(parent.lastChild);
> >         }
> > }
>
> > Is there a shorter jQuery way to do this function. Ideally, it could
> > start with a reference to the source element object instead of an
> > elementid so I can avoid the use of ids in form elements.
>
> > And of course, what's the advantage to the jQuery way? Less code?
> > Slickers?
> > Cliff

Reply via email to