-1

i need to use jplayer add to playlist in my joomla website and i will when user click on icon of play , jquery get the data-mp3 and data-name and data-poster from tag link and add to above function to add that sound in player please help me how did it? i cant get data-* attribute and send to myplaylist.add function for add that sound data to playlist of jplayer

$("#playlist-equivalent-1-a"). click(function() {
    myPlaylist.add({
        title:"title",
        artist:"artist",
        mp3:"url",
        poster: "url"
    }, true);
});
  • Check: https://stackoverflow.com/questions/5309926/how-to-get-the-data-id-attribute and: https://stackoverflow.com/questions/33760520/get-data-attributes-in-javascript-code – Slipoch Oct 31 '19 at 23:48
  • Does this answer your question? [get data attributes in JavaScript code](https://stackoverflow.com/questions/33760520/get-data-attributes-in-javascript-code) – Slipoch Oct 31 '19 at 23:49

1 Answers1

0

You're in luck, jQuery has a built-in function for retrieving data-* attributes: https://api.jquery.com/data/.

Example: Get the mp3 title and artist from an anchor tag

$('#datatag').click(function() {
  $('#output').text($('#datatag').data('title') + ' from ' + $('#datatag').data('artist') + ' is a really good song!');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<a data-artist="De Jeugd van Tegenwoordig" data-title="Sterrenstof" id="datatag">Click me to reveal my data.</a><br>
<span id="output"></span>
Fdebijl
  • 887
  • 5
  • 20
  • It's not a correct answer. Implement your code to the OP example. OP knows about `data-*`. – Aksen P Oct 31 '19 at 21:59
  • i need send that attr to myPlaylist.add and run this function after it for example myPlaylist.add({ title:"Sterrenstof ", artist:"De Jeugd van Tegenwoordig ", mp3:"your url", poster: "your url" }, true); and after set this attr run this function – mohammad javad jabbari Oct 31 '19 at 22:28
  • @mohammadjavadjabbari could you clarify a bit more? If I got it right you want to: 1. Get data attributes from some element 2. Pass them to `myPlaylist.add` 3. Run a function (which one?) – Fdebijl Nov 01 '19 at 08:24
  • @Fdebijl first i need Get data attributes from some element then Pass them to myPlaylist.add then run myPlaylist.add function because this function add that music data to my playlist of jplayer -- jplayer with playlist demo : http://jplayer.org/latest/demo-02-jPlayerPlaylist/ -- A project similar to my topic : http://zakerin.ir – mohammad javad jabbari Nov 02 '19 at 11:07