1

I have the following HTML line:

<div data-component-id="12345" class="component" data-component-status="operational">

Is it possible to use the data-component-id as a CSS Selector?

I would like to add a CSS code especially for this div, eg: {display: none}

2
  • 2
    It's called attribute selector: div[data-component-id="12345"] {} Commented Jan 23, 2020 at 13:53
  • Also you can read MDN Docs aboutn attribute selector. Commented Jan 23, 2020 at 13:55

1 Answer 1

8

You can use the Attribute selector [] for this

div[data-component-id="12345"] {
  background-color: red;
}
<div data-component-id="12345" class="component" data-component-status="operational">
  Demo
</div>

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.