0

Could I add data attributes to an element via it's CSS?

.myClass{
/* assign data attribute here */
}
2
  • 2
    data attributes aren't CSS... Commented Aug 30, 2012 at 20:33
  • You could easily achieve selector/data pairs with a JavaScript object. Commented Aug 30, 2012 at 20:36

3 Answers 3

5

CSS is for presentation not data(manipulating markup).

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

Comments

2

No, it is not possible. You'd have to use something else, like javascript.

Comments

1

No, that is not what CSS should be used for. The idea of CSS is precisely to be all about the presentation and not at all about the data. What you may do, if you have to, is to have different possible values in different elements, and change by CSS which element is visible.

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.