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
Christopher Portillo
13,787 PointsJavascript question involving thumbnail image click to main image
Hi, I have a javascript code that I used to replace the main image with a thumbnail image when its click. I have this instance happening in more then one place in the website. How can I get this javascript code to work with multiple parts of the website?
function ChangeImage(a) {
document.getElementById("viewer").src = a;
}
1 Answer
Catherine Gracey
11,521 PointsI would change it to the following:
function ChangeImage(a, elementID) {
document.getElementById(elementID).src = a;
}
The second argument, element, will take a string that is the ID of whatever you want to change.
Chyno Deluxe
16,936 PointsChyno Deluxe
16,936 Points//Fixed Code Presentation
How to post code