1

I want to hide a few divs on a website. Each of them has its own data-title. Can I use this CSS code? I guess I should do this by using:

 {display: none;}

However, I have a big problem with producing the correct selector.

Divs unfortunately do not have names, and class - and they can only be distinguished by the data-title. I will be grateful for any help.

user3845582
  • 105
  • 1
  • 15
user3282071
  • 131
  • 1
  • 2
  • 7

1 Answers1

4

You can target elements by its properties on css with the selector element[property="value"], so:

div[data-title="something"] {
    display: none;
}

EDIT

About the comment's below on "use or not quotes" on css property selector, there was a question answered here on SO that covers the subject: CSS attribute selectors: The rules on quotes (", ' or none?)

Community
  • 1
  • 1
LcSalazar
  • 16,524
  • 3
  • 37
  • 69
  • @RaduAndrei Can you give more information about which browsers? A link would be nice. The spec says it's not needed if the attribute is a valid CSS identifier. http://stackoverflow.com/a/7286343/227299 – Ruan Mendes Aug 25 '14 at 15:35
  • Oddly, I've always had more problems with Chrome when I *do* quote the attribute-value (so now I use redundancies: `div[data-title=something], div[data-title="something"] {...}`). – David Thomas Aug 25 '14 at 15:36
  • Thanks a lot! Exactly what I meant. Let me still small, quick question. To hide I have a really large number of divs. Can I therefore build a common selector for several different divs, so as to simplify the code as possible? – user3282071 Aug 25 '14 at 15:48
  • 1
    You can select multiple elements separating them with a comma: `div[data-title="1"], div[data-title="2"], div[data-title="3"] { display: none; }` – LcSalazar Aug 25 '14 at 15:50
  • Thank you, now I know everything – user3282071 Aug 25 '14 at 15:53