Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4016720
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:46:28+00:00 2026-05-20T09:46:28+00:00

I was just curious what’s the best way to store data for use by

  • 0

I was just curious what’s the best way to store data for use by JQuery – I’m setting up a basic mp3 player, and the title, artist, track and file name all need be held somewhere to be retrieved by JQuery upon clicking in the radio interface. I was thinking of storying them as simple attributes within an tag, like this:

<a href="{song_file}" data-title="{song_title}" data-artist="{song_artist}" data-album="{song_album}">

but I’m guessing that might be considered bad form. I know I could bring them in via XML, but I’d rather not have to retrieve from some external document. Anybody have a good solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:46:29+00:00Added an answer on May 20, 2026 at 9:46 am

    I believe what you are looking for is jQuery’s .data(): http://api.jquery.com/jQuery.data/

    Here is one possible way it can be done:

    <div id="songs"></div>
    
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
    <script>
        jQuery(function() {
    
            // The following array can be trivially generated directly from your data,
            // by PHP's json_encode(), or your language's equivalent:
            var songs = [
                {
                    file: '/path/to/song.mp3',
                    title: 'A Day in the Life',
                    artist: 'The Beatles',
                    album: 'Sgt. Pepper\'s Lonely Hearts Club Band',
                }
                // ...
            ];
    
    
            var wrap = jQuery('#songs');
            for (var i=0, ii=songs.length; i<ii; i++) {
                jQuery('<a></a>')
                    .text(songs[i].title)
                    .attr('href', songs[i].file)
                    .data('song-data', songs[i])
                    .click(click_handler)
                    .appendTo(wrap);
            }
    
            // then, you can retrieve the data like this:
            function click_handler() {
                var data = jQuery(this).data('song-data');
                alert('Album was: '+data.album);
                return false;
            }
    
        });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just curious if anyone knows a quick way to use ucwords() on a string
Just curious, is there a format string I can use to output something like
Just curious what is the best practice for solving the following issue. I have
Just curious to know what the best practice would be for something like this:
Just curious - apart from its ubiquitous use in specifying the presentation of HTML
Just curious if this is the way to do this, just want to make
Just curious if there is a way to find the number of keys in
Just curious if there's a way in netbeans to give type hints for regular
Just curious to see people's opinions: Has anyone thought about implementing the Flash player
just curious - is there a shorter way to achieve this? latest_date = date1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.