Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1000013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:26:40+00:00 2026-05-16T07:26:40+00:00

I am new to jQuery and I am having trouble with the syntax, selectors

  • 0

I am new to jQuery and I am having trouble with the syntax, selectors and refining when trying to create functions. I was hoping someone might be able to help.

What I am trying to achieve:

I have a gallery consisting of a ul with images placed in vertically stacked list items. The ul is in a fixed size wrapper with overflow:hidden so only the first list item displays. The user clicks a button and the first li is hidden using hide(400). This makes the other list items flow up and reveals the second list item within the wrapper window.

When the last list item is visible, the click will show(400) all of the list items again, causing them to flow back into order and only the first item will be showing again.

Further clicks will repeat this process from the beginning.

I know what I would like to do in terms of code, but I am having trouble with the correct syntax, selectors and refining.

I have included the html and description version of the code I was hoping to create. I know the code could be much more efficient by placing functions into varibles and testing for true false, but I would like to see the steps with my longer code description for learning purposes. Perhaps afterwards someone can blast it off in two lines.

Regardless, thanks to anyone who can help with this. I love the possibilities of jQuery and look forward to learning more.

Thanks in advance!
ThomUI

   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>list hiding test</title>
<style>
.listWrapper {
height:25px;
width:380px;
background-color:#d6d6d6;
float:left;
font-size:18px; 
margin:0; 
list-style:none;
overflow:hidden;
}
span { color:blue; text-decoration:underline; cursor:pointer; }
.example { font-style:italic; }
a.nextItemBtn {
background-color:#888888;
cursor:pointer;
width:120px;
height:120px;
float:left;
}
</style>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>

<body>

  <ul class="listWrapper">
    <li ><a href=""><img src="" />pic 1</a></li>
    <li ><a href=""><img src="" />pic 2</a></li>
    <li ><a href=""><img src="" />pic 3</a></li>
    <li ><a href=""><img src="" />pic 4</a></li>
  </ul>
 <a class="nextItemBtn"><img src="" />see more</a>

<script>

var listLength = 4; //number of li items in the ul, this will be dynamic, here we test with 4
var listCounter = 0; //show(400) all list items once we reach the end (listLength -1)
var listPosition = [0]; //the first spot in the returned set of matched elements, incremented at each click()

$(".nextItemBtn").click(function () {//click nextItemBtn

if (listCounter == listLength -1) {//if we reach the end of the list, make the entire list visible again using show(400)
    $(".listWrapper li").show(400); //show all list items
    listCounter = 0;//reset the listCounter, this will allow the user to see the first list item again while the rest remain overflow:hidden
    listPosition = [0];//reset list position
}
else {
    $(.listWrapper li[listPosition]).hide(400);//get the first li in listWrapper and hide(400)
    listCounter ++;//add one to the number of li items we have hidden
    listPosition ++;//add one to the index position so next click() the second li in listWrapper will hide(400), next time the third etc 
    //I'm pretty sure you can't stick a variable in for an index number... doh!
}
});

</script>

</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:26:41+00:00Added an answer on May 16, 2026 at 7:26 am

    Try this:

    var listLength = 4; //number of li items in the ul, this will be dynamic, here we test with 4
    var listCounter = 0; //show(400) all list items once we reach the end (listLength -1)
    
    $(".nextItemBtn").click(function () {//click nextItemBtn
    
    if (listCounter == listLength -1) {//if we reach the end of the list, make the entire list visible again using show(400)
        $(".listWrapper li").show(400); //show all list items
        listCounter = 0;//reset the listCounter, this will allow the user to see the first list item again while the rest remain overflow:hidden
    }
    else {
        $('.listWrapper li').eq(listCounter).hide(400);//get the first li in listWrapper and hide(400)
        listCounter ++;//add one to the number of li items we have hidden
    }
    });​
    

    I’ve removed your listPosition array (which wasn’t being used properly). Look up the JQuery eq function if you’re not familiar with it.

    Demo here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble getting tinyMCE to work with the new jQuery 1.4.2 on IE6.
I am new to jQuery and am having trouble following the documentation. I have
I'm fairly new to jQuery and I'm having trouble with an animation that I'd
I'm very new to JQuery, and I'm having some trouble understanding how to do
New to javascript/jquery and having a hard time with using this or $(this) to
i'm relatively new to jquery and javascript and am trying to pass a unique
Thanks for reading. I'm a bit new to jQuery, and am trying to make
I was going through the source code of jQuery. I'm having trouble understanding the
I am new to jQuery and am trying to fire a function on a
I'm having trouble getting the jquery ui 1.8 dialog to center I've tried leaving

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.