I have a div with a string inside of it. I want to change that string if something specific happens. I am not sure why but I can't get the string to change at all even if there is no conditional. I am very rusty to JavaScript so any advice would be appreciated, I am slowly getting back to the basics.
<div class="cell text-center" id="changeString"> Report has not yet been pulled for this organization.</div>
var bananas = true;
if (bananas = true){
document.getElementById('changeString').innerHTML = "You have successfully run the report.";
}
Can anyone see what I am doing wrong? I have also tried putting the JS into a function and calling it in the div with onload="methodName".
getElementById(changeString)and the=in the if should be==or===.=is assignment,==and===are comparisonchangeStringis a variable that refers to the DOM element.getElementByIdhowever expects to be passed a string value. So either dochangeString.innerHTML = ...ordocument.getElementById('changeString').innerHTML = ...var bananas = true; console.log(bananas); if (bananas == true){ document.getElementById("changeString").innerHTML = "You have successfully run the report."; }This still doesn't work but I can see in the console that it is returning true.scripttags jsfiddle.net/maio/8qt9fzjr/2