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 9225711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:39:00+00:00 2026-06-18T04:39:00+00:00

I have an element I need to get an array of specific attributes. For

  • 0

I have an element I need to get an array of specific attributes.
For example:

<div id="myDiv" class="myClass" data-country="US" data-city="NY" />

In this example, I need to get all data-* attributes and place them in array (name and value pairs).

In this example, final array would look like this:

myDataArray["data-country"] = "US";
myDataArray["data-city"] = "NY";

Problem is that these attributes are dynamic, I do not know what attributes will be there at the runtime and I cannot hard code filling of array.

  • 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-06-18T04:39:01+00:00Added an answer on June 18, 2026 at 4:39 am

    You can call data() to get all data attributes.

    Live Demo

    myDataArray = $('#myDiv').data();
    alert(myDataArray["country"]);
    alert(myDataArray["city"]);
    

    You can iterate through key value pair like this,

    Live Demo

    arr = $('#myDiv').data();
    
    for(el in arr)
    {
        alert("Key >> " + el);
        alert("Value >> " + arr[el]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to have data structure, each element in which is accessible by pair
I have a Mootools class that creates an element. I need to add a
I have a char array and I need to get the address of each
I need a data structure in which each element has a specific index but
I have an array and I need to get out of it array, without
I need some sort of dynamic array in C++ where each element have their
I have an array of data get from the server(ordered by date): [ {date:2012-8,
I have a system where I need to get codes for specific positions. There
I have the string SUM([A2:A10],[B2:B10],[C2:C10],[D2:D10]) and I need to get the elements [A2:A10],[B2:B10],[C2:C10],[D2:D10] in
I need to find an a -tag's ID by its style. My element have

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.