//My js file has the following
$mytag.popover({
html:true,
trigger: hover,
container: $mytag,
template: '<div class="popover" role="showDetails">' +
...//other
'</div>',
content:'<div class="info">' +
...//other
'<div class="myrow">' +
'<span>' + 'Result:' + '</span>' +
'<span>' + item.result + '</span>' +
+ '</div>' +
});
The value of item.result is calculated elsewhere (js). The final outcome is expected to be a Boolean value. I'd like to append a css class here instead of displaying the outcome. Eg: If item.result is true. I'd like to add class="ok" to the span tag.
'<span class="ok">' + '</span>' +
If item.result returns false. I'd like to add class="notOk" to the span tag.
'<span class="notOk">' + '</span>' +
Can someone please advise what is the best way to achieve this?.
Thanks in advance.
you can achieve this with string interpolation.
`<span class="${calcutationFn() ? 'ok' : 'noOK'}"> ... </span>`
Have you tried adding an id
to the span
and then using the element.classlist.add('class_name')
function? Add an if statement where the item.result
is calculated to add the class to the span like:
if (item.result) {
document.getElementById("result-span").classList.add("ok");
}
else {
document.getElementById("result-span").classList.add("notOk");
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.