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
https://forums.phpfreaks.com/topic/187903-help-with-jquery-array-and-links/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.