Tilføje link til text i javascript
Hej Eksperter.Jeg har dette script, som jeg fandt på nettet som automatisk viser nogle billede og noget tekst.. Men mit problem er at jeg gerne vil have at når man klikker på billedet eller teksten, så skal det linke til en side nogle der kan hjælpe?
-----------------------KODE----------------------
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Test</title>
<style type="text/css">
#images_container{
overflow:hidden;
width:150px;
}
#images_container .image_box{
float:left;
width:150px;
text-align:center;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
var image_list = [
{
url: 'http://i1.ytimg.com/vi/4wt824D1Bqg/default.jpg',
caption: 'This is a random image 1'
}
,{
url: 'http://i3.ytimg.com/vi/VVI7Z8kOyvA/default.jpg',
caption: 'This is a random image 2'
}
,{
url: 'http://i3.ytimg.com/vi/zWHd4u0mBWs/default.jpg',
caption: 'This is a random image 3'
}
,{
url: 'http://i3.ytimg.com/vi/J-Psu-x-KSA/default.jpg',
caption: 'This is a random image 4'
}
,{
url: 'http://i4.ytimg.com/vi/c4ys61-A-eo/default.jpg',
caption: 'This is a random image 5'
}
,{
url: 'http://i3.ytimg.com/vi/VfVYVYl8Fq8/default.jpg',
caption: 'This is a test'
}
,{
url: 'http://i1.ytimg.com/vi/DjoNt2viUz0/default.jpg',
caption: 'This is a test'
}
,{
url: 'http://i2.ytimg.com/vi/anlZc0T8rfo/default.jpg',
caption: 'This is a test'
}
]
$(function(){
var used = [];
var i = Math.floor(Math.random() * image_list.length);
while (used.length < 4){
while ($.inArray(i, used) > -1){
i = Math.floor(Math.random() * image_list.length);
}
img = image_list[i];
$('<div class="image_box"><img src="' + img.url + '" alt="' + img.caption + '"><p>' + img.caption + '</p></div>').appendTo('#images_container');
used[used.length] = i;
}
});
</script>
</head>
<body>
<div id="images_container"></div>
</body>
</html>
------------------------KODE------------------------
Mvh. Jeppe S