So I'm working on my first site which is basically gonna be a site with a picture in the middle which randomizes if you click a button. I've done an array that look like this, except the images and links (obviously) aren't the ones I use. var myImages = new Array(); myImages[1] = "oneee.jpg" myImages[2] = "twooo.jpg" myImages[3] = "threee.jpg" myImages[4] = "ffourrr.jpg" var myLinks = new Array(); myLinks[1] = "link one" myLinks[2] = "link two" myLinks[3] = "link three" myLinks[4] = "link four" + I've added the randomizing code. It all works. But now I wanna add some text under the images and I can't figure out how. Anyone that can help me?
Mhhh... since I don't know the rest of the code, I don't know how your randomization works. For my suggestion, I assume you use a random number (between 1-4) and with that number, you choose the image and link. Well, easiest would be to create a new array with the text for the images (match the index of the new array with the index of myImages[]) and then insert it into your randomizer.
This is the tutorial I used. Yeah I was thinking about making a new text array. But I don't know how the array should look... This is what my head tells me to write. var myText = new Array(); myText[1] = "Hello this is cool" myText[2] = "Bye bye" myText[3] = "Images are awesome" myText[4] = "Badoobie do" But first, I don't know if it's the right code to use. Second, I don't know how to write the code into the document.write code.
Well, it's almost right, you just need to ad a semicolon at the end var myText = new Array(); myText[1] = "Hello this is cool"; myText[2] = "Bye bye"; myText[3] = "Images are awesome"; myText[4] = "Badoobie do"; Code (markup): And then you could add it to the document.write like this document.write('<a href="'+myLinks[rnd]+'"><img src="'+myImages[rnd]+'" /></a><p>'+myText[rnd]+'</p>'); Code (markup):
Do you know how to do if I wanna change color on the texts in the array? Can't figure out how to do it. Have tried everything I know of...
You want to change the text colour? No problem. For simplicities sake, we are going to use inline css. document.write('<a href="'+myLinks[rnd]+'"><img src="'+myImages[rnd]+'" /></a><p style="color: red">'+myText[rnd]+'</p>'); Code (markup): You see the style="color: red"? That changes the colour of the text within the <p> tags.