vendredi 30 janvier 2015

how to separate two variables

I have this codes,and my problem is that the image and the text appears in one div. How can I separate the text and display it to another div while the image appears also on another div. but still when i reload the page, image 1 will correspond to text 1.same with image 2 it should also appear with text 2.



<html>
<head>
<meta charset=utf-8 />
<title>Random Text Plus Image</title>
</head>
<body>
<div id="quote"></div>
<script>
(function() {
var quotes = [
{
text: "text1",
img: "image1.jpg"
},
{
text: "text2",
img: "image2.jpg",
}
];
var quote = quotes[Math.floor(Math.random() * quotes.length)];
document.getElementById("quote").innerHTML =
'<p>' + quote.text + '</p>' +
'<img src="' + quote.img + '">';
})();
</script>
</body>
</html>




Aucun commentaire:

Enregistrer un commentaire