I'm trying to change the text within a p
tag on load using JavaScript, using the first character of that p
tag. The p
tag is populated using Flask double curly brackets syntax, i.e {{yourstring}}
.
A variable is calculated in Python and either a 1 or 0 is returned and then added to a string at index 0. That string is then pulled into the HTML as the {{trailing_check}}
variable.
I want my js function to change the value in that first index to say 'tick' or 'cross' (will later be an image) based on whether the value is a 1 or 0.
However, nothing seems to be happening... please see my code below.
HTML
<div class="summary" onload="good_outcome()">
<p id = "trailing_check">{{trailing_check}}</p>
</div>
JS
function good_outcome(){
if(document.getElementById("trailing_check").innerHTML.charAt(0) == '1'){
document.getElementById("trailing_check").innerHTML = "tick"
}
else{
document.getElementById("trailing_check").innerHTML = "Cross"
}
What am I doing wrong?