0

In following HTML snippet, I am trying to modify the text dynamically using CSS.

<li id="onroad" class="onroad boxSizing" data-stageid="4" data-invalidot="1" data-desc="Heading your way">
                <span class="material-icons ui-state-default ui-state-active" aria-hidden="true"></span>
                <h4 class="text" role="none">On Road</h4>
                    <span class="line ui-state-default ui-state-active" aria-hidden="true"></span>
</li>

My CSS snippet is,

#trackerDiv>#trackerNav>ol#tracker.delivery li#onroad span.ui-state-active  h4 {visibility: hidden;}
#trackerDiv>#trackerNav>ol#tracker.delivery li#onroad span.ui-state-active h4:before {visibility: visible;position: absolute;content: "Complete";}

So my ask is without using JS/Jquery to dynamically change the text based on "ui-state-active" class presence. CSS looks alright but it ain't working.

If above CSS executes correctly, it should replace "On Road" to "Complete"

3
  • 1
    Dynamically changed by user event such as clicking? Commented Sep 14, 2021 at 20:07
  • You cannot make the child elements visible if the host element has visibility: hidden. Commented Sep 14, 2021 at 20:10
  • 1
    @connexo Actually, yes you can. visibility /= opacity Commented Sep 14, 2021 at 20:11

1 Answer 1

3

Your CSS is incorrect, the h4 is not a child of the span it's a sibling so use +, like so

ul {
  list-style: none;
}

li#onroad span.ui-state-active+h4 {
  visibility: hidden;
}

li#onroad span.ui-state-active+h4:before {
  visibility: visible;
  content: "Complete";
}
<ul>
  <li id="onroad" class="onroad boxSizing" data-stageid="4" data-invalidot="1" data-desc="Heading your way">
    <span class="material-icons ui-state-default ui-state-active" aria-hidden="true"></span>
    <h4 class="text" role="none">On Road</h4>
    <span class="line ui-state-default ui-state-active" aria-hidden="true"></span>
</ul>

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.