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
Adam Chamberlain
390 PointsLimitation for append() in Jquery
Hi,
I am using the append() method to append new colors in the colors panel, and am trying to limit the new colors to only 5. Adding many colors without limitation to the panel might look weird and I don't want that. So any ideas of how to do that?
Thanks
1 Answer
Steven Parker
243,656 Points
You could add a variable to keep a count of how many colors there are.
Each time you add a color, increment the value of the variable and compare it with your limit. If the limit has been reached, disable or remove the "add" button from the document.