jQuery arrays - newbie needs a kick start

Posted by Jonny Wood on Stack Overflow See other posts from Stack Overflow or by Jonny Wood
Published on 2010-05-26T07:31:26Z Indexed on 2010/05/26 7:41 UTC
Read the original article Hit count: 244

Filed under:
|
|
|

I've only really started using this site and alredy I am very impressed by the community here! This is my third question in less than three days. Hopefully I'll be able to start answering questions soon instead of just asking them!

I'm fairly new to jQuery and can't find a decent tutorial on Arrays. I'd like to be able to create an array that targets several ID's on my page and performs the same effect for each.

For example I have tabs set up with the following:

$('.tabs div.tab').hide();
        $('.tabs div:first').show();
        $('.tabs ul li:first a').addClass('current');
        $('.tabs ul li a').click(function(){
            $('.tabs ul li a').removeClass('current');
            $(this).addClass('current');
            var currentTab = $(this).attr('href');
            $('.tabs div.tab').hide();
            $(currentTab).show();
            return false;
        });

I've used the class .tag to target the tabs as there are several sets on the same page, but I've heard jQuery works much faster when targetting ID's

How would I add an array to the above code to target 4 different ID's? I've looked at

var myArray = new Array('#id1', 'id2', 'id3', 'id4');

And also

var myValues = [ '#id1', 'id2', 'id3', 'id4' ];

Which is correct and how do I then use the array in the code for my tabs...?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about beginner