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

  • Home
  • SEARCH
  • 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 5972295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:38:16+00:00 2026-05-22T20:38:16+00:00

What is the proper way of separating my meta-data from the HTML? As my

  • 0

What is the proper way of separating my meta-data from the HTML? As my projects grow bigger and bigger tying up meta-data with HTML becomes more and more messy. Any good alternatives?

Meta Data: Everything the JS needs to know about an HTML element which isn’t straight-forwardly encoded in the HTML elements and their attributes. E.g. a geolocation, enabled, disabled action.

Example: Say I have a list of places I want to show up on a map whenever I click on one of them. How do I identify that exact same place in JS so I could tell the map ‘hey, move to that location’? Easiest way, that becomes messy in the end, is to tie it into the HTML, say the li id will be the geolocation. That’s easy, but it is a code smell. How do I do this properly? .data() in jQuery also becomes horrible to maintain soon afterwards.

Conclusion: that’s it, I’m going to find/write good MVC for JS.

  • 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-22T20:38:16+00:00Added an answer on May 22, 2026 at 8:38 pm

    If you want to attach metadata to DOM elements then use HTML5 data- attributes or use jQuery’s .data() method to do it programmatically.

    Here’s a real world example I just used it on that really helped. I sent a request to the server to upload a file and I get a JSON response with the File Name, Content Type, Size and a GUID. On the response I want to add a list item to show the file but I want to preserve the JSON data. Here’s how I did it in the callback:

    function(response) {
      $('<li>').text(response.fileName).data('metadata', response).appendTo('ul');
    }
    

    What’s great about this is now the list item HAS all my metadata attached to it.

    So I could do something like this and know everything about it:

    var metadata = $('ul li:eq(1)').data('metadata');
    
    alert(metadata.contentType);
    alert(metadata.size);
    
    //etc..
    

    The implementations are really limitless.

    ALSO, as of jQuery 1.4.3 .data() will automatically pick up the data- attributes in your HTML. So <div data-foo="bar"></div> can be immediately accessed in code using $('div').data('foo') //bar

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

Sidebar

Related Questions

While searching for a proper way to trim non-breaking space from parsed HTML, I've
What's the proper way to encode untrusted data for HTML attribute context? For example:
What's the proper way to add a literal text value from a field to
What is the most proper way to sending email of minimal 1000 or more
What is the proper way for transfering complex objects from iOS app to Unity3D
Possible Duplicate: Proper way to make HTML nested list? I'd like to produce the
In Winforms what is proper way to keep a user from changing the value
What is the proper way to use stdafx.h , in terms of separating dependencies?
Is there any proper way to detect the environment (development or production) in the
What's the proper way to convert from a scientific notation string such as 1.234567E-06

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.