function sync_animations(abc) {
abc.dataset.chosen = abc.value;
for (let a of document.getAnimations()) {
a.startTime = 0;
}
}
select[data-chosen] {
outline-offset: 2px;
outline: 12px solid;
}
select[data-chosen='green'] {
outline-color: green;
}
select[data-chosen='red'] {
outline-color: red;
}
select[data-chosen='grey'] {
outline-color: grey;
}
select[data-chosen='blinkgreen'] {
outline-color: green;
animation: blink 2s;
animation-iteration-count: infinite;
}
select[data-chosen='blinkred'] {
outline-color: red;
animation: blink 2s;
animation-iteration-count: infinite;
}
@keyframes blink {
100% {
outline-offset: 2px;
outline: 12px solid;
outline-color: transparent;
}
}
<select onchange="sync_animations(this)" id="select_nonsdwan_37">
<option value="blinkgreen">Running (Fine)</option>
<option value="blinkred">Running (Issues)</option>
<option value="green">Completed (Fine)</option>
<option value="red">Completed (Issues)</option>
<option value="grey" selected="selected">Yet to start</option>
</select>
I can see the border around the select when I change the value of select via the UI.
But when I set the value via javascript, it does not show the animation.
2
Answers
The
change event
only triggers when there are user-initiated changes. Modifications made through JavaScript in the background, which we call manipulation, do not trigger thechange event
.When manipulating the value attribute of your
<select>
element using JavaScript, you should call yoursync_animations()
function and pass the select element to it. See the example below.Adding the attribute change works properly.