javascript - Someone please help me with this soundcloud api -


this question has answer here:

this html , js file:

window.onload = function(){  	sc.initialize({  		client_id: "f5311a935daa5ecf6440f92183e77df1"  	});  	  	var menulinks = document.getelementsbyclassname("genre");  	for (var i=0; < menulinks.length; i++){  		var menulink = menulinks[i];  		menulink.onclick = function(e){  			e.preventdefault();  			playsounds(menulink.innerhtml);  		};  	};  };    function playsounds(genre){  	sc.get('/tracks', {genres: genre}, function(tracks){  		var random = math.floor(math.random()*49);  		sc.oembed(tracks[random].uri, {autoplay: false}, document.getelementbyid("content"));  	});  };
<html>  <head>  	<title>soundcloud api</title>  	<script type="text/javascript" src="script.js"></script>  	<script src="//connect.soundcloud.com/sdk-2.0.0.js"></script>  </head>    <body>  <ul>  <li><a href="#" class="genre">electronic</a></li>  <li><a href="#" class="genre">trap</a></li>  <li><a href="#" class="genre">dubstep</a></li>  </ul>    <div id="content"></div>  </body>  </html>

so when click on of links, should search particular genre instead searches dubstep no matter link click on. can please help?

replace

playsounds(menulink.innerhtml); 

with

playsounds(this.innerhtml); 

the reason did not work when click on link, menulink, equals last 1 defined in loop (<a>dubstep</a>).


Comments