CSS "inner-html" technique? [duplicate]
Asked Answered
D

3

10

I was wondering if there was a way to query elements according to the word it contains. So, if I have:

<div id="globalPageHeader">
    <h1>Home</h1>
</div>

I want any #globalPageHeader h1 that has the word Home in it, to have a display property of none.

Obviously this example wouldn't work, but I was wondering if there's something like it:

#globalPageHeader h1(innerHTML == "Home") {
     display: none;
}

I don't want to use JavaScript's innerHTML because I have no access to the javascript parts of the admin.

Any help is much appreciated!

Dessert answered 26/3, 2013 at 2:5 Comment(2)
There used to be a contains() pseudo class - but it was removed for who knows why - however, jQuery still supports it in their sizzle selectorUnscreened
#5442180Percolate
C
22

With pure CSS, that’s impossible.

Caenogenesis answered 26/3, 2013 at 2:8 Comment(1)
Ahh. Okay, I was afraid of that. Thanks!Dessert
B
5

This is not possible using CSS. You can, however, do it using jQuery. Why not just add a class to the desired h1 tags?

Beni answered 26/3, 2013 at 2:11 Comment(1)
Yeah, I would do that, except since it's global, it's a lot of work. Plus, no jQuery because I don't have access to the JavaScript side of the admin. Thanks, though!Dessert
C
3

I had a similar problem. What you can do is to add an attribute to the <h1> element. For example title :

<div id="globalPageHeader">
    <h1 title='Home'>Home</h1>
</div>

And then in the CSS:

#globalPageHeader h1[title = 'Home'] {
     display: none;
}

It worked for me.

Carp answered 16/9, 2014 at 8:7 Comment(1)
Why not just add a class?Submergible

© 2022 - 2024 — McMap. All rights reserved.