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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:05:39+00:00 2026-06-14T19:05:39+00:00

I am developing a kind of HTML+JS control which can be embedded into various

  • 0

I am developing a kind of HTML+JS control which can be embedded into various web pages. I know nothing about those pages (well, I could, but I don’t want to). The control consists of one root element (e.g. DIV) which contains a subtree of child elements. In my script, I need to access the child elements. The question is: how can I mark those child elements to distinguish them?

The straightforward solution is using id-s. The problem here is that the id must be unique in the scope of the entire document, and I know nothing about the document my control will be embedded into. So I can’t guarantee the uniqueness of my id-s. If the id-s are not unique, it will work (if used with care), but this does not conform with the standard, so I can meet problems with some new versions of the browsers, for example.

Another solution is to use the “name” attribute. It’s not required to be unique — that’s good. But again, the standard allows the presence of “name” attribute only for a restricted set of element types. For example, the “name” attribute is invalid for DIV elements.

I could use, for example, the “class” attribute. It seems to be OK with the standards, but it’s not OK with the meaning. “class” should be used for other purposes, and this may be confusing.

Can anybody suggest some other options to implement local id-s for HTLM elements?

  • 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-14T19:05:39+00:00Added an answer on June 14, 2026 at 7:05 pm

    You could use the HTML5 data-* attributes so you can give them a custom name with the right meaning:

    https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes

    Do something like:

    <div id="element-id" data-local-id="id-value">
      ...
    </div>
    

    and get the value in JavaScript with:

    const el = document.getElementById('element-id');
    const { localId } = el.dataset;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing user control in C# Visual Studio 2010 - a kind of quick
I'm kind of new in web development with Java. I am developing a web
I am developing a web app in which I am trying to use the
I am developing a web application, part of which contains a the ability to
I am developing a static website using HTML/CSS. I have 7 pages in my
I am developing a php script which contains an html form. If not all
In the application I am developing, I need to create documents which can be
I'm developing some kind of plugin which should be called by external java app.
I am developing an html/javascript app which allows users to search in a local
I'm developing a kind of a chat for a website and I can't imagine

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.