I've just started learning html and CSS and now I want to add a bit JavaScript which I don't know anything of!
I want to create a random button that shows a random embed video (for instance from 1-5 videos) in a iframe. I searched google and found a JavaScript/(jQuery?):
<script type="text/javascript" src="jquery-1.11.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var array=["Item1", "Item2", "Item3", "Item4", "Item5"];
$('#button').bind('click', function() {
var random = array[Math.floor(Math.random() * array.length)];
$("h1").html(random);
});
});
</script>
With the html:
<h1>Will be replaced</h1>
<button id="button">Random</button>
So for example in my html I got:
<iframe width="640" height="360" src="http://www.youtube.com/embed/npvNPORFXpc" frameborder="0" allowfullscreen></iframe>
I want this embedded video to show on the page and when u hit the random button it should change to 1-5 video's. How do i set this as a item in the JavaScript, so I have a video on each item?
Problem 2:
Sometimes the same number is generated which will lead to the same item.
I hope someone can teach me something about this!
<iframe id="video">can be selected with$("#video")and then you can set the src attribute using$("#video").attr("src", newUrlHere)api.jquery.com/attr