I start with html, css, js and more. Now I want to create a site where I have an image, and if someone clicks this image, I should play a random song from a playlist or something like that. I have a valid code to activate one song, but if I want to have more than one song, it no longer works ...
(html and js documents are on my computer, I have not downloaded it yet, so don't ask questions ^^)
<html>
<head>
<title>title</title>
<link type="text/css" rel="stylesheet" href="style.css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="script.js"></script>
</head>
<body>
<div id="headline">
<h1 id="hl">Headline</h1>
<img class="play" id="pic" src="pic.png"/>
<img class="pause" id="pic2" src="pic.png"/>
</div>
</body>
</html>
$(document).ready(function() {
$(".pause").css ('display', 'none');
$(".play").click (function(){
$(".play").css ('display', 'none');
$(".pause").css ('display', 'inline-block');
});
$(".pause").click (function(){
$(".play").css ('display', 'inline-block');
$(".pause").css ('display', 'none');
});
var audioElement = document.createElement('audio');
audioElement.setAttribute('src', 'song1.mp3');
$.get();
audioElement.addEventListener("load", function() {
audioElement.play();
}, true);
var x = 1 ;
if (x = 1) {
$('.play').click(function() {
});
}
$('.pause').click(function() {
audioElement.pause();
audioElement2.pause();
});
});
(Maybe the code is not perfect, but as I said: it works)
Now I want to have more than one song, and I do not want to use a music player or so. There is no way to solve this problem using html, js and jQuery (maybe css too, but I think this is not necessary, right?)?