I’m not too familiar with HTML/CSS and I have a UI model pointing to this HTML/CSS code. I want to change the text color of ‘Sample Text’ below based on if the table value for let’s say, when the #MAP#PPOINDIVIDUAL_value placeholder is empty or null. Right now I have this, but it doesn’t seem to be changing it to red when the table is empty.
document.addEventListener("DOMContentLoaded", function () {
var rows = document.querySelectorAll("#MAP#PPOProspectTileViewDataForm tr[id$='_container']");
var hasValue = false;
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
var valueSpan = row.querySelector("span[id$='_value']");
if (valueSpan && valueSpan.innerText.trim() !== "") {
hasValue = true;
break;
}
}
var headerLink = document.querySelector("#MAP#PPOProspectTileViewDataForm .bbui-forms-summarytile-headerlinkcontainer a");
if (!hasValue) {
headerLink.style.color = "#999999";
}
});
##MAP#PPOProspectTileViewDataForm td {
padding-top: 0px;
padding-bottom: 0px;
}
.#MAP#BOLD {
font-weight: bold;
}
.#MAP#CAPTION {
padding-right: 5px;
}
##MAP#LOOKUPID_value {
width: 80px;
}
##MAP#STATUS_value {
width: 55px;
}
##MAP#MEMBERSHIPLEVELNAME_value {
width: 180px;
}
.#MAP#DATATABLE {
border-spacing: 2px 1px;
}
##MAP#ISPRIMARY_value {
margin-right: 0px;
}
##MAP#ISPRIMARY_container,
##MAP#PRIMARYMEMBERLINK_container {
padding-left: 0px;
height: 16px;
}
##MAP#STATUS_caption {
padding-left: 7px;
}
a.#MAP#BOLD:empty {
color: red;
}
<div id="#MAP#PPOProspectTileViewDataForm">
<div class="bbui-forms-fieldset-row">
<div class="bbui-forms-summarytile-headerlinkcontainer">
<a class="#MAP#BOLD">Sample Text</a>
</div>
</div>
<div class="bbui-forms-fieldset-row">
<table>
<tr id="#MAP#PPOINDIVIDUAL_container">
<td class="#MAP#SHRINKCELL">
<span id="#MAP#PPOINDIVIDUAL_caption" class="bbui-forms-summarytile-caption"></span>
</td>
</tr>
<tr>
<td>
<div class="bbui-forms-summarytile-headerlinkcontainer">
<span id="#MAP#PPOINDIVIDUAL_value"></span>
</div>
</td>
</tr>
<tr id="#MAP#PPOORGANIZATION_container">
<td style="width: 300px;">
<span id="#MAP#PPOORGANIZATION_caption" class="bbui-forms-summarytile-caption"></span>
</td>
</tr>
<tr>
<td>
<a id="#MAP#ORGLINK_action"><span id="#MAP#PPOORGANIZATION_value"></span></a>
</td>
</tr>
<tr id="#MAP#PPOTEAM_container">
<td>
<span id="#MAP#PPOTEAM_caption" class="bbui-forms-summarytile-caption"></span>
</td>
</tr>
<tr id="#MAP#PPOTEAM_container">
<td>
<a id="#MAP#PROSPECTASSIGNMENT_action"><span id="#MAP#PPOTEAM_value"></span></a>
</td>
</tr>
</table>
</div>
</div>
3
Answers
I refuse to go along with the pre-existing ID and CSS names on principle since it is SO bad to do so; AND produced invalid HTML.
Now to answer the question you can use the
:has
for exampleUsing the existing invalid and confusing IDs/classes, you reference the span with getElementById and simply toggle a class on the anchor based on the length of the textContent of the span.
First of all, I am going to assume that these IDs and class names are replaced with valid values through the UI model…
Second, your example is applying styling if the
a
with "sample text" itself is empty instead of when the intendedspan
is empty. To achieve what you want, you can use the:has()
pseudo-class on the parent element along with the~
adjacent sibling combinator that matches the parent container of the emptyspan
and then style the id of thea
.bbui-forms-fieldset-row:has(~ .bbui-forms-fieldset-row ##MAP#PPOINDIVIDUAL_value:empty) .#MAP#BOLD