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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:32:31+00:00 2026-05-29T10:32:31+00:00

I am using jQuery 1.4.3. I am trying to determine a best practice for

  • 0

I am using jQuery 1.4.3.

I am trying to determine a best practice for using data-* attributes. In the recent past, I have created checkboxes like this:

<input type='checkbox' id='123' class='Product' comp='1' man='1'>
<input type='checkbox' id='456' class='Product' comp='1' man='2'>
<input type='checkbox' id='789' class='Product' comp='2' man='3'>

The HTML 5 spec says that I shouldn’t use custom attributes and that I should use data-* attributes. Which means that the above checkboxes should really be like this:

<input type='checkbox' id='123' class='Product' data-comp='1' data-man='1'>
<input type='checkbox' id='456' class='Product' data-comp='1' data-man='2'>
<input type='checkbox' id='789' class='Product' data-comp='2' data-man='3'>

That’s easy enough to accomplish, but with jQuery, I would usually call these elements by their id, which in this case happens to be the actual product id. So, my code to access these would be like this:

$(".Product").click(function() {
    var ProductID = $(this).attr("id");
    alert(ProductID );
});

Since the ID is really just a piece of data that I need to access, it should be a data-* attribute instead of an id. I think what I really should be doing is this:

<input type='checkbox' class='Product' data-prodid='123' data-comp='1' data-man='1'>
<input type='checkbox' class='Product' data-prodid='456' data-comp='1' data-man='2'>
<input type='checkbox' class='Product' data-prodid='789' data-comp='2' data-man='3'>

This means that the id is no longer necessary for storing data, because I can do this:

$(".Product").click(function() {
    var ProductID = $(this).attr("data-prodid");
    alert(ProductID );
});

And if I want to check or uncheck a specific GROUP of boxes, I can do something like this:

// WHEN A PRODUCT IS CLICKED 
$(".Product").click(function() {
    // GET THE COMP
    var Comp = $(this).attr("data-comp");
    // UNCHECK BOXES WITH A DISSIMILAR COMP THAN THE ONE CLICKED
    $("[data-comp]!="+Comp).attr("checked", false);
});

It really seems like I can accomplish everything I need without using the id for storing data. Am I wrong? Is this how I should implement microdata storage? Is it correct that I will no longer need the id attribute except for CSS layout? Am I missing anything?

  • 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-29T10:32:32+00:00Added an answer on May 29, 2026 at 10:32 am

    Using ID has its own meaning in HTML,CSS and Javascript.

    • ID in HTML defines an unique element meaning it must be unique in a
      document.

    • ID in CSS applies styling rules to a specific block or element.

    • ID in JS will allow you to retrieve the element using
      document.getElementById.

    You don’t have any of those meaning when you use data attribute.

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

Sidebar

Related Questions

I have a simple html block like: <span id=replies>8</span> Using jquery I'm trying to
how to determine the child of a UL using jquery? im trying to change
I have 2 dropdown lists on my webform and using jquery trying to filter/reset
Using Chrome's developer tools I am trying to determine what jQuery function is hooking
I am trying to upload a file using jQuery ajax, but keep getting this
Using jQuery I am trying to set focus for (CSS purposes) to a particular
using jquery ui 1.8 trying autocomplete Everything works apart from that the ui-menu isn't
I am trying to find a way using jquery without cookies to display a
I am trying to get an element using JQuery's selector, but it does not
I'm trying to load fragments of XHTML markup using jQuery's $.fn.load function, but it

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.