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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:07:30+00:00 2026-06-16T20:07:30+00:00

With all the respect to Html5 data attribute When I have a code like

  • 0

With all the respect to Html5 data attribute

When I have a code like this:

 <li class="user" data-name="Royi Namir" data-city="Boston" data-lang="js" data-food="Bacon"> </li>

I’m adding quite a lot of redundant chars into the document.

I only need this type of data-XXX in order to do :

myDomElement.dataset[xxx];

However , I could easily do this

<li class="user" dn="Royi Namir" dc="Boston" dl="js" df="Bacon"> </li>

Without those extra data- prefixes (and save me a lot of extra chars). and to read it via “start with ” selector like [d^] – jQuery API

Am I missing something here ?

  • 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-16T20:07:31+00:00Added an answer on June 16, 2026 at 8:07 pm

    You could use this :

    <li class="user" data-user='{"name":"Royi Namir", "city":"Boston", "lang":"js", "food":"Bacon"}'> </li>
    

    And then

    var user = JSON.parse(element.dataset.user);
    

    Using jQuery, it’s even simpler :

    var user = $(element).data('user');
    

    And if you want to get all your users :

    var ​users = $('[data-user]').map(function(){return $(this).data('user')});
    

    There would be less redunduncy and a directly usable structure, especially with deeper properties. Data attributes aren’t only for strings.

    But the main point about data- attributes is to normalize a practice. Now it’s clear when looking at the HTML, what attributes are standard HTML (view) attributes and what attributes are data ones (specific to your application logic).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some markup like this (classes are just for explication): <ol id=root class=sortable>
Our investigations have shown us that not all browsers respect the HTTP cache directives
All, I have couple of queries with respect to displaying html: I have a
With respect to the following code segment, I would like to know whether my
It's my first post so sorry if I may not respect all the conventions
All, If I run a query like the following: $qry = Select wrong_column from
All -- I have these two methods in one of my classes: public static
All, Apologies in advance - this question might be too open-ended for SO. Anyway...
All my code is here,quite simple,and I don't konw where it goes wrong. Person
I would like to stop my application playing a sound if the user has

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.