Hide paragraph based on content

Hi,

is it possible to hide specific p based on the content?
i.e.

<p>this is normal visible text</p>
<p>myconditionaltext to hide</p>

Make the first show, and hide the second.
I know I can add class or id, but need to do it based on content.

If possible how could it be done?

Thank you

Not with CSS. Javascript can though, easily. Are you open to that?

technically speaking , Ryand answered this. CSS has no content selectors.

I am curious, why would you ever need to hide something based on content (or rather if you knew you needed to hide that content for some nefarious reason, it might be simpler to add a class to the element.

other than that you could cheat. That is, you can’t select based on content, but you can select based on VALUE.

which means if you could create hidden inputs, with the value of the content to hide, PRIOR to you event and then use [value=] and adjacent selector to hide the element.

eg.:

input[value="some content i want hidden"]+* { display:none; }

of course this is just unnecessarily convoluted, since, if you could know the content and alter the source by builiding a hidden input, why not just add a class?

Just guessing, but it sounds like it may be time for a bit of CREATE TABLE and / or ALTER TABLE to make things easier. No fault intended, unfortunately it is not easy to plan for the unknown and inconceivable

How about:

div p:nth-child(2)  {
                display: none;
            }

with:

<div>
    <p>this is normal visible text</p>
    <p>myconditionaltext to hide</p>
</div>

But isn’t that based on the element’s selector and not the node’s content as keneso is wanting to do?

OK, I get it now, I was missing the keyword “myconditionaltext”.
Yes, that needs scripting.
But what script would the OP like to use? JS, PHP, what?

Thank you all.

I was just curious, no specific need as of now; I am experimenting with a drupal site where some users might be “content editors” thus creating content, since drupal way of adding content is based on preset forms, and basically the output is predictable, I was thinking to kinda use a filtering method for few specific (forseeable) content that is going to be inside a paragraph.

I thought it would be easier in css, but since that’s not an option, I am open to both js and php.

Please note being just an experiment, and not knowing how to do it, I don’t expect you losing time on this, just say no, it’s perfectly understandable, unless you see it as a challenge, and want to experiment yourself.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.