I am using Watupro plugin for simple test. In result window there are variables that display numeric test results: %%CATEGORY-POINTS-4%%
, %%CATEGORY-POINTS-5%%
etc.
I am using Progress Bar plugin, to display progress bar with results via shortcode.
[wppb progress=%%CATEGORY-POINTS-4%%/130 option=green]
gives me nice progress bar, based on student’s results in each category.
However I want to display different colors of progress bar, depending on result. In order to achieve that, I want to change value of shortcode, based on numeric values.
I came up with this code so far:
HTML:
<div class="bar" data-score="%%CATEGORY-POINTS-4%%">[wppb progress=%%CATEGORY-POINTS-4%%/130 option=green]</div>
<div class="bar" data-score="%%CATEGORY-POINTS-5%%">[wppb progress=%%CATEGORY-POINTS-5%%/130 option=green]</div>
<script type="text/javascript">
results();
</script>
JavaScript:
function results() {
var bar = document.getElementsByClass('bar');
var score = bar.getAttribute('data-score');
alert (score);
if (score < 47) {
// ???
}
if (score > 46 && 4_score < 71) {
// ???
}
if (score > 70) {
// ???
}
I guess I need to come up with code that changes shortcode attribute option
to different color for each div respectively.
Any ideas?
2
Answers
Ok. I got it solved. I added loop, so, Javascript goes through all divs.
Here's the code:
Working example here: https://codepen.io/nick-gregory-the-looper/pen/wvympmg
Since you are using WP, you can try jQuery like this:
Then create new CSS class yellow: