4

Let's say we have:

<div id="view-item-hero-info">
    <h2>{{name}}</h2>
    <h4>{{location}}</h4>
    <h3>
        <span id="view-item-hero-header-score">
            You scored {{userScore}}pts
        </span>
    </h3>
    {{description}}
</div>

Is there a way I can hide the text directly inside #view-item-hero-info? I know I can use text-indent but is there another, nicer, way?

Note: I don't want to hide the element, just everything inside it.

Note 2: Hiding all the elements within #view-item-hero-info is fine, I can use #view-item-hero-info > * { display: none } but then the text directly within #view-item-hero-info is still visible. I need #view-item-hero-info to remain visible so that its background can be seen but the text inside it must be hidden.

Ahmed Nuaman
  • 12,662
  • 15
  • 55
  • 87

6 Answers6

3

You can try:

#view-item-hero-info {
    color: transparent;
}
AnnanFay
  • 9,573
  • 15
  • 63
  • 86
2

Using this CSS:

visibility: hidden;

hides your element, but preserves the space it would normally take. Whereas this CSS will hide an element as if it never existed:

display: none;
jgoldberg
  • 455
  • 5
  • 11
1

you can use this code if u need hide text

.text-hidden{
   font-size: 0;
   text-indent: -9999px;
}

to hide all direct child's use

.hidden-nested > *{
    visibility: hidden; /*or next line */
    display:none ;
}

if you need all child's use last code but change class to

 .hidden-nested  * 
Albaz
  • 905
  • 12
  • 21
0

Use css display property. In HTML this would look like <span style="display: none">

Using javascript: document.getElementById("view-item-hero-header-score").style.display="none"

in css:

#view-item-hero-header-score {
   display: none;
}
Matt Fellows
  • 6,512
  • 4
  • 35
  • 57
0

Using CSS you can set a style:

visibility:hidden  

So to hide all descendants (*) within your element:

#view-item-hero-info * { visibility: hidden }

If instead you only want to hide direct descendants ie children but not grandchildren then you use the direct child selector (>)

Rather than selecting all (*) you can select particular descendants eg divs:

#view-item-hero-info div { visibility: hidden }

Equally instead of the visibility you can use:

display:none

The display option doesn't take up space whereas if you want to reserve the space for when the element will be shown you use the visibility option

EDIT: There isn't a selector just for a text node (ie the text without the element). See Is there a CSS selector for text nodes?. So all children of your span need to be in an element in order to have style applied.

As a hack you could just put another span directly in your main one and all content (including the standalone text) within that. Then the hiding will work.

Community
  • 1
  • 1
kaj
  • 5,133
  • 2
  • 21
  • 18
0

Could you use JS to iterate though all child items in the elements DOM and then use JS to overwrite the CSS? Something like:

var items_i_want = document.getElementById("view-item-hero-header-score").elements

for(var i = 0; i < items_i_want .length; i++)
{
    items_i_want [i].style.display="none"
}
Mark Ursino
  • 31,209
  • 11
  • 51
  • 83