As MorningZ said, use .index(). When you have a collection of elements
in a jQuery object, use .index() and pass the element you wan the
index of to the function.

var stepslist = $("#stepsList li");
stepslist.click(function() {
        // load stepContent  ===> not a problem
        $("#stepFooter").html("Viewing step "+(stepslist.index(this)+1)+" of
"+stepslist.length);
})



On Mar 5, 6:13 am, MorningZ <morni...@gmail.com> wrote:
> There is also the ".index" functionality
>
> http://docs.jquery.com/Core/index
>
> On Mar 5, 7:31 am, "Adam Jessop" <a.jes...@sivltd.com> wrote:
>
> > Give the li's an ID and just use that for the step number
>
> > e.g:
>
> > <li id="step-1">Step one</li>
> > <li id="step-2">Step two</li>
>
> > Then:
> > <script>
> > $("#stepsList li").click(function() {
> >   // load stepContent  ===> not a problem
>
> >    id = $(this).attr('id');
> >    $("#stepFooter").html("Viewing "+ id.replace("-"," ") +" of  
> > "+$("#stepsList li").length);
>
> > })
>
> > </script>
>
> > Un tested but you get the idea...
>
> > -----Original Message-----
> > From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On
>
> > Behalf Of Liam Byrne
> > Sent: 05 March 2009 12:25
> > To: jquery-en@googlegroups.com
> > Subject: [jQuery] Current item child index ?
>
> > Hi folks
>
> > Just wondering if there's a quick/shorthand way of doing this:
>
> > I'm doing a navigation system where I want clickable items but I want to
>
> > put the "current item number" in a footer, e.g.
>
> > Any ideas of a quick way (without using each) to get "CURRENTSTEPNUMBER"
>
> > ? Basically the reverse of nth-child ?
>
> > CODE OUTLINE (IF IT HELPS) :
>
> > <script>
> > $("#stepsList li").click(function() {
> >   // load stepContent  ===> not a problem
>
> >    $("#stepFooter").html("Viewing step "+CURRENTSTEPNUMBER+" of  
> > "+$("#stepsList li").length);
>
> > })
> > </script>
>
> > <h1>STEPS TO BE COMPLETED</h1>
> > <ul id="stepsList">
> > <li>step one</li>
> > <li>step two</li>
> > </li>step three<li>
> > </ul>
>
> > <div id="stepContent">
>
> > <div id="stepFooter">
> > </div>
> > </div>
>
> > *************************************************************************** 
> > ********************************
> > IMPORTANT INFORMATION & CONFIDENTIALITY NOTICE
> > The information in this e-mail is confidential and may be legally 
> > privileged.
> > It is intended solely for the named recipient.  Access to this Email by 
> > anyone else is unauthorised.
> >  If you are not the intended recipient or the employee or agent responsible 
> > for delivering the message to the recipient named,
> > please note that any use, disclosure, copying, distribution of this e-mail 
> > or any action taken or omitted to be taken in reliance on it is
> > prohibited.  If you are not the intended recipient, please inform us by 
> > returning a copy of the e-mail with the subject
> > line marked "wrong address" and then deleting the e-mail, and any 
> > attachments and any copies of it.  Any questions should be directed
> > to  postmas...@sivltd.com.
>
> > Sheffield International Venues Limited uses regularly updated anti-virus 
> > software in an attempt to reduce the possibility
> > of infection. However we do not guarantee that any attachments to this 
> > e-mail are virus free.
>
> > *************************************************************************** 
> > ********************************

Reply via email to