html - jquery put a value instead of selector name -


hello how usualy select element name

<div id="song-name"></div>  <a href="#" id="play">play</a> <a href="#" id="pause">pause</a> <a href="#" id="skip">next</a> <a href="#" id="previous">previous</a> <br><br>    <audio  id="1"   name="song1" class="audio-player" src="music.mp3"></audio>    <audio id="2" name="song2" class="audio-player" src="music2.mp3"></audio>      var songname=$("1").attr("name"); 

but need

   var id=1;         songname=$("id").attr("name"); 

what write syntax it?

i need because have script show current music playing name,but show first song name if next song playing

   <script>     $(document).ready(function() {     var x = $(".audio-player").length;     var z = 0;      var songname=$("audio").attr("name");       $("#play").click(function(){         $(".audio-player")[z].play();         $("#song-name").text(songname);         $("#song-name").show();     })     $("#pause").click(function(){         $(".audio-player")[z].pause();         $("#song-name").hide();     })     $("#skip").click(function(){          $(".audio-player")[z].pause();         z++;         if (z >= x) z = 0;           $(".audio-player")[z].play();          $(".audio-player")[z].currenttime = 0;         $("#song-name").text(songname);          $("#song-name").show();       })         $("#previous").click(function(){         $(".audio-player")[z].pause();         z=z-1;         if (z >= x) z = 0;         $(".audio-player")[z].play();         $(".audio-player")[z].currenttime = 0;         $("#song-name").text(songname);     })     });     </script> 

so edit #skip function

       $("#skip").click(function(){              $(".audio-player")[z].pause();     //where edit            var  id=id+1;         var songname=$("#id").attr("name"); //finish edit              z++;             if (z >= x) z = 0;               $(".audio-player")[z].play();              $(".audio-player")[z].currenttime = 0;             $("#song-name").text(songname);              $("#song-name").show();           }) 

use string concatenation + operator:

var id = 1; var songname = $("#" + id).attr("name"); // "#" + id => "#1"  

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -