0

I realize my title isn't perfectly clear, but I couldn't come up with a better one. So here goes:

I work on an e-commerce website where different products should have different maximum order ammounts. Since writing plugins for the CMS is not really an option, I want to solve this with javascript.

What I want to do:

  1. Check wether a div with the class "order-limit" exists
  2. Read that divs data-limit-attribute, which contains a number
  3. Add a sentence including the number

Now today I read http://danwebb.net/2010/1/27/put-that-data-attribute-away-son-you-might-hurt-someone which basically said:

Don't use data-* attributes for javascript.

So now I wonder: What's the best practice to do what I did, given that products have different upper limits?

1
  • What he's saying is you shouldn't use data attributes when HTML or Javascript already provide features to do what you want (like href and hidden fields). It should be used when the data is semantically relevant to the element. Commented Jun 5, 2014 at 9:55

1 Answer 1

1

I think this quote from the article you've linked is self-explanatory enough:

By all means, use data-* attributes to add semantically valuable data to your HTML but if you are just using it to prop up a script you are writing think again.

By the way, I don't believe there's a BEST way, only the best way for your specific situation and needs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.