New to Javascript. Attempting to make an onClick gallery for a personal site

Go To


So I'm new to Javascript and while I've looked around at as much as I could understand I don't really know what I'm doing or looking for at all.

MY GOAL: I am making a gallery and for the items that have multiple views or images I want to give the corresponding thumbnails an onClick function that will change out the displayed img and p.

EXAMPLE: An item in the gallery has 4 images I want to display. When the item is selected, the page loads with the first of the 4 images and some copy displayed along with 4 thumbnails. When any of the 4 thumbnails are selected, the image and copy will change.

My syntax skill are lacking drastically (I'm literally just getting past "Hello World") but based on the very little that I know I would assume that I would be trying to do something like the following:

HEAD --> script --> var img="imgID" var p="pID";

function onload (default, "image1", "copy1");

function onClick display (imgID, pID)

<-- script <-- HEAD

Body --> div -->

img id="get imgID" p id="get pID"

<-- div

div -->

img id="thumb1" onClick imgID="image1" pID="copy1";

img id="thumb2" onClick imgID="image2" pID="copy2";

img id="thumb3" onClick imgID="image3" pID="copy3";

img id="thumb4" onClick imgID="image4" pID="copy4";

<-- div <-- Body

As I mentioned, since I am new to this, I don't fully understand the limitations of functions, or display or default or how to properly pull var values so if anyone has any thoughts on if this is fairly simple or how to get this to work - or may be able to recommend any tutorials to start with that are more object based please let me know.

Thank you in advance


2012-04-04 04:29
by user1311848


It seems like you might want to do a little more reading before you try and jump into something like this. Code Academy is awesome for learning JavaScript. It'll introduce you to the syntax and the main ideas.

I'd also check out some of the resources listed in other Stack Overflow questions:

Just stay away from W3 Schools and you'll be fine.

Once you get more comfortable with the language, jQuery is a good library to look into. It'll make what you're trying to do much easier.

2012-04-04 04:38
by LandonSchropp
Here's the full list of JavaScript tutorials on Code Academy: - LandonSchropp 2012-04-04 04:41
Thanks! I've been taking the CodeAcademy courses and learned a LO - user1311848 2012-07-12 05:28

0 seems to have a pretty good beginning tutorial as well.

2013-07-24 22:22
by Amaranda


Looks like you'll be using '.innerHTML', and '.src' quite a lot. Do some research on them.

2015-06-22 17:18
by user2072826