Jump to content

help with jquery array and links


CyberShot

Recommended Posts

I am using jquery to make my own navigation for some pagination. I know how to do it this way

 

I have a list

 

  <ul class="pages">

   </ul>

<ul class="pages">

   </ul>

<ul class="pages">

   </ul>

<ul class="pages">

   </ul>

 

So that is 4 ul's with the class of pages. So I can use jquery to pick that up in an array by doing

 

$(".pages:eq(0)").show();

 

that would show the first ul, I could hide all other pages by doing $(".pages").hide();

 

simple enough.

 

Now I want to make a link for the pagination, so I do this

 

<a href="#" class="pageLink">1</a> <a href="#" class="pageLink">2</a> <a href="#" class="pageLink">3</a> <a href="#" class="pageLink">4</a>

 

and I wrote a click event for it like so

 

$(".pageLInk:eq(1)").click(function(){
{
      $(".pages").hide();
      $(".pages:eq(1)").show();
}

That's about as simple a pagination script I can get. I don't think it gets simpler than this. Here is my issue. I want to make it a little more complicated but can't figure out how. I wanted to put the pages into a variable so I wouldn't have to type it out all the time like this

var page1 = $(".pages:eq(0)");
var page2 = $(".pages:eq(1)");

 

OR

 

var page1 = $(".pages:eq(0)",".pages:eq(1)");

 

This is what I thought it would be, but of course I was wrong. Can you tell me how to fix this?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.