I'm new to javascript and cannot figure out why this is not setting the visibility of the image to normal when IsImportant is true. I can see by inspecting the page that the if statement is being populated with true or false, but it doesn't affect the visibility.
Any help appreciated, thanks
@using DomainLayer.DTOs
@model MessageDto
<script type="text/javascript">
function setImportantFlag()
{
if (@Json.Encode(Model.IsImportant))
{
document.getElementById('importantFlag').style.display = 'normal';
}
}
</script>
<img id="importantFlag" src="~/Images/important.png" style="display:none; height:100px; width:100px" />
@Html.Encode(Model.Title)<br />
@Html.Encode(Model.Author), @Html.Encode(Model.PublishDate)<br />
@Html.Encode(Model.Body) <br />
<br />
http://stackoverflow.com/questions/ask#
Edit:
The page looks like this
<script type="text/javascript">
function setImportantFlag()
{
if (false)
{
document.getElementById('importantFlag').style.display = 'normal';
}
}
setImportantFlag();
</script>
<img id="importantFlag" src="/Images/important.png" style="display:none; height:100px; width:100px" />
Big ol deibufouebwf<br />
, 01/01/0001 00:00:00<br />
<br />
<br /><script type="text/javascript">
function setImportantFlag()
{
if (true)
{
document.getElementById('importantFlag').style.display = 'normal';
}
}
setImportantFlag();
</script>
<img id="importantFlag" src="/Images/important.png" style="display:none; height:100px; width:100px" />
News article one<br />
Author One, 13/06/2016 21:49:04<br />
Well if it isn&#39;t body one! <br />
<br />
ready()function: so the script isn't executed until the elements exist.