Hey there!
So I’m trying to do something a little complicated for Webflow. I’m stuck on how to tackle this problem and I’m wondering if anyone can help. Basically, I’m trying to create a table graph that shows a user the results of a likert scale graph.
I got some code that works well to make it show up like this:
<!-- Add this CSS code to your <head> section -->
<style>
.tf-bg-color {
display: inline-flex;
align-items: center;
justify-content: center;
width: 25px;
height: 25px;
border-radius: 50%;
padding: 5px;
color: #FFFFFF;
font-size: 24px;
font-weight: bold;
}
.tf-bg-no-color {
display: inline-flex;
align-items: center;
justify-content: center;
width: 25px;
height: 25px;
border-radius: 50%;
padding: 5px;
color: #000000;
font-size: 24px;
font-weight: bold;
background-color: #DDDDDD;
}
</style>
<!-- Add this HTML code to your page for each element you want to show/hide -->
<div id="q1a" class="tf-bg-color">1</div>
<div id="q1a-no-color" class="tf-bg-no-color">1</div>
<div id="q1b" class="tf-bg-color">2</div>
<div id="q1b-no-color" class="tf-bg-no-color">2</div>
<div id="q1c" class="tf-bg-color">3</div>
<div id="q1c-no-color" class="tf-bg-no-color">3</div>
<div id="q1d" class="tf-bg-color">4</div>
<div id="q1d-no-color" class="tf-bg-no-color">4</div>
<div id="q1e" class="tf-bg-color">5</div>
<div id="q1e-no-color" class="tf-bg-no-color">5</div>
<!-- Add this JavaScript code to the end of your <body> section -->
<script>
const elements = document.querySelectorAll('.tf-bg-color');
function showElement(element) {
element.style.display = 'inline-flex';
}
function hideElement(element) {
element.style.display = 'none';
}
function toggleElement(element, value) {
if (element.innerText === value.toString()) {
showElement(element);
} else {
hideElement(element);
}
}
const variable = 1; // Replace with your variable
for (let i = 0; i < elements.length; i++) {
const id = elements[i].id;
toggleElement(elements[i], variable);
if (id) {
const noColorElement = document.querySelector(`#${id}-no-color`);
if (noColorElement) {
if (elements[i].style.display === 'none') {
showElement(noColorElement);
} else {
hideElement(noColorElement);
}
}
}
}
</script>
My question is how can I make this work for multiple rows? I’m stuck on how to make this work for multiple questions and I’m wondering if anyone has any suggestions.
Here is my site Read-Only: Webflow - The Attributes