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

Aquib Javed
8,289 PointsHow to create an upvote/downvote button using javascript(or anything for that matter)?
I want to build a voting button from scratch that'll only have the upvote and downvote options. Can someone help me here please?
1 Answer

Laura Cressman
12,548 PointsHi Aquib, I was actually working on this awhile ago, and would love to share my pen with you: http://codepen.io/hilaura13/pen/ztmpf
I use jQuery here, I think that the code will probably speak for itself, but the main idea is to have a variable that records the total votes, and change it depending on whether they clicked the up vote or down vote button. Then, set the text of the vote total to the new value of counter. Hope that helps, would be happy to discuss further! Smile more, Laura :)
Ryan Duchene
Courses Plus Student 46,022 PointsRyan Duchene
Courses Plus Student 46,022 PointsAwesome pen, Laura. Obviously, you'd need something on the backend to actually turn this into an application, but this is a really good start.
Aquib Javed
8,289 PointsAquib Javed
8,289 PointsThanks a bunch Laura, really appreciate the help. One thing, can you kindly tell me about the '%'-s you used in the #margin? I mean the calculation, they're basically for the right and left margin, but got stuck a bit understanding the '%' part.