i want to show div (bsically target is to show card so placed it inside div ) on Django Template when if condition becomes True.I set the div display property to "none" and on django template when the variable exists (check by if condition ) the hidden div (and card inside it) must be shown .I have searched many solutions and tred all of these like but could not get my desired result.
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
#myDIV {
display: none;
}
</style>
</head>
<body>
<script>
function showAlert() {
document.getElementById("demo").innerHTML = "you have to give test";
var x = document.getElementById("myDIV");
if (x.style.display === 'none') {
x.style.display = 'block';
}
}
</script>
{% if pretest_random_ques %}
<script>
showAlert()
</script>
{% endif %}
{% for e in pretest_random_ques %}<!--Works fine -->
{{e.question.question}}
{% endfor %}
<div id="demo" style="color:green;"></div>
<div id="myDIV">
<div class="card" style="width:18rem;">
<div class="card-image waves-effect waves-block waves-light">
<img class="activator" src="static/img/1.jpg">
</div>
<div class="card-content"><a href="/pretest"><span class="card-title activator grey-text text-darken-4">Take A Pre-Test<i class="material-icons right">more_vert</i></span></a></div>
<div class="card-reveal">
<span class="card-title grey-text text-darken-4">Pre-test<i class="material-icons right">close</i></span>
<p>Its a test to test your previous knowledge.</p>
</div>
</div>
</div>
</body>
</html>
the output shows nothing (means it did not show the hidden div also did not show the .innerhtml value in div having id="demo").Any suggestion regarding this will highly be appreciated . Thanks in advance.