[jQuery] Re: li:nth-child(10) toggle

2009-06-20 Thread bombaru
Works like a champ! Thank you again (mkmanning and karl) for all of your help. On Jun 19, 9:16 pm, bombaru bomb...@gmail.com wrote: Thanks mkmanning!!!  I'll give this a try tomorrow and let you know. Looking at it though... I'm pretty confident it will do the trick. It's amazing how much

[jQuery] Re: li:nth-child(10) toggle

2009-06-20 Thread bombaru
One question with this approach... how would I implement this only on groups that contain more than 10 LI's? Right now it's getting added to every LI group. Groups with less than 10 LI's are also getting the more link appended but there is obviously nothing to toggle. Thanks again. This

[jQuery] Re: li:nth-child(10) toggle

2009-06-20 Thread bombaru
You are a rock star! I can't thank you enough. On Jun 20, 1:55 pm, mkmanning michaell...@gmail.com wrote: A minor refactor then: $('.main ul').each(function(){ var $this = $(this), lis = $this.find('li:gt(9)').hide();         if(lis.length0){        

[jQuery] Re: li:nth-child(10) toggle

2009-06-20 Thread mkmanning
A minor refactor then: $('.main ul').each(function(){ var $this = $(this), lis = $this.find('li:gt(9)').hide(); if(lis.length0){ $this.append($('li').text('More').click(function(){ lis.toggle(); $(this).text($(this).text() === 'More' ?

[jQuery] Re: li:nth-child(10) toggle

2009-06-19 Thread Karl Swedberg
I'd probably use .slice(). Something like this should work: $(document).ready(function() { var $list = $('.main ul'), $items = $list.find('li'), $moreLink = $('a href=#more/a'); if ($items.length 10) { $moreItems = $('ul/ul').append($items.slice(10)).hide();

[jQuery] Re: li:nth-child(10) toggle

2009-06-19 Thread bombaru
Thanks Karl... I'm not familiar with slice() but will definitely read up on it. The problem I'm having with this approach is that every LI after the 10th one is being hidden. Here's an example of what the HTML looks like without any JS applied to it: ul id=narrow-search li class=main

[jQuery] Re: li:nth-child(10) toggle

2009-06-19 Thread mkmanning
Try this: $('.main ul').each(function(){ var $this = $(this), lis = $this.append($('li').text('More').click (function(){ lis.toggle(); $(this).text($(this).text() === 'More' ? 'Less' : 'More'); })).find('li:gt(9):not(:last)').hide(); }); Since you

[jQuery] Re: li:nth-child(10) toggle

2009-06-19 Thread mkmanning
And you can shorten it slightly: $('.main ul').each(function(){ var lis = $(this).append($('li').text('More').click(function(){ lis.toggle(); $(this).text($(this).text() === 'More' ? 'Less' : 'More'); })).find('li:gt(9):not(:last)').hide(); }); I

[jQuery] Re: li:nth-child(10) toggle

2009-06-19 Thread Karl Swedberg
Ah, I see. Helps to be able to see the HTML. Let us know if mkmanning's approach doesn't do the trick. --Karl Karl Swedberg www.englishrules.com www.learningjquery.com On Jun 19, 2009, at 5:56 PM, bombaru wrote: Thanks Karl... I'm not familiar with slice() but will

[jQuery] Re: li:nth-child(10) toggle

2009-06-19 Thread bombaru
Thanks mkmanning!!! I'll give this a try tomorrow and let you know. Looking at it though... I'm pretty confident it will do the trick. It's amazing how much more efficiently the original chunk of code can be written and it still makes perfect sense (actually it's clearer). On Jun 19, 7:36 pm,