Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Julie Vandebosch
10,360 PointsLet index start at 1 (jQuery)
Hey all,
I am new to jQuery and I would like to know how I can let the index start at 1 instead of 0.
Here is my code:
$('.sort-options').on('change', function() {
var ind = $(this).find('option:selected').index();
$(".filter li:eq("+ind+")").find('a').click();
});
What I am trying to do: I have a filter for a portfolio. I'm using isotope for this. The filter is in an ul on most screens, but on mobile I am showing a select dropdown. The code I am showing here is to make the filter work on the select. But this one has an extra (disabled option), so the index should start at 1 instead of 0 (atleast I think so).
Jacob Mishkin
23,118 PointsIn JavaScript/Jquery all lists/index are 0 based. You might want to use the :gt() Selector in Jquery, this might help. Here is the documentation:
https://api.jquery.com/gt-selector/
I hope this helps, if not let us know what you come up with.
Gunhoo Yoon
5,027 PointsGunhoo Yoon
5,027 PointsFrom reading the document it seems like there isn't a way to internally set the index to 1. However, can't you use if statement to ignore case where index is 0?