I’m unable to show/hide divs. It gives me error cannot read property style from null
.
Any help would be appreciated.
function HideAllShowOne(d) {
// Between the quotation marks, list the id values of each div.
var IDvaluesOfEachDiv = "w11 W12 W21 w31";
//-------------------------------------------------------------
IDvaluesOfEachDiv = IDvaluesOfEachDiv.replace(/[,s"']/g, " ");
IDvaluesOfEachDiv = IDvaluesOfEachDiv.replace(/^s*/, "");
IDvaluesOfEachDiv = IDvaluesOfEachDiv.replace(/s*$/, "");
IDvaluesOfEachDiv = IDvaluesOfEachDiv.replace(/ +/g, " ");
var IDlist = IDvaluesOfEachDiv.split(" ");
for (var i = 0; i < IDlist.length; i++) {
HideContent(IDlist[i]);
}
ShowContent(d);
}
function HideContent(d) {
document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
document.getElementById(d).style.display = "block";
}
function ReverseDisplay(d) {
if (document.getElementById(d).style.display == "none") {
document.getElementById(d).style.display = "block";
} else {
document.getElementById(d).style.display = "none";
}
}
<div id='menu' class="col-sm-4">
<ul>
<li>
<a class='text-center'>
<img src='student/student.jpg' class='img-responsive img-circle ' width='100px' height='100px' style=' float:none; ' />
</a>
</li>
<li><a href='#'><b>harsha lenka</b></a>
</li>
<li><a href='#home'>Home</a>
</li>
<li class='active has-sub'><a href='#'>Week 1</a>
<ul>
<li><a href=javascript:HideAllShowOne( 'w11')>Back propagation Algorithm</a>
</li>
<li><a href=javascript:HideAllShowOne( 'w12')>Introduction</a>
</li>
</ul>
</li>
<li class='has-sub'><a href='#'>Week 2</a>
<ul>
<li><a href=href=javascript:HideAllShowOne( 'w21')>Introduction</a>
</li>
</ul>
</li>
<li class='has-sub'><a href='#'>Week 3</a>
<ul>
<li><a href=href=javascript:HideAllShowOne( 'w31')>Introduction</a>
</li>
</ul>
</li>
<li class=' has-sub'><a href='#'>Assignments</a>
<ul>
<li class='has-sub'><a href='#'>Mid Term 1</a>
<ul>
<li><a href='#'>Assignment 1</a>
</li>
<li><a href='#'>Assignment 2</a>
</li>
</ul>
</li>
<li class='has-sub'><a href='#'>Mid Term 2</a>
<ul>
<li><a href='#'>Assignment 1</a>
</li>
<li><a href='#'>Assignment 2</a>
</li>
</ul>
</li>
</ul>
</li>
<li><a href='#'>About</a>
</li>
</ul>
</div>
<div id="ved_dat" class="col-sm-8">
<div id='#w11' style='display:none;'>
<video width='500' height='500' controls>
<source src='courses/Artificial Intelligence/week1/Back propagation Algorithm.mp4' type='video/mp4'>Your browser does not support the video tag.</video>
</div>
<div id='#w12' style='display:none;'>
<video width='500' height='500' controls>
<source src='courses/Artificial Intelligence/week1/Introduction.mp4' type='video/mp4'>Your browser does not support the video tag.</video>
</div>
<div id='#w21' style='display:none;'>
<video width='500' height='500' controls>
<source src='courses/Artificial Intelligence/week2/Introduction.mp4' type='video/mp4'>Your browser does not support the video tag.</video>
</div>
<div id='#w31' style='display:none;'>
<video width='500' height='500' controls>
<source src='courses/Artificial Intelligence/week3/Introduction.mp4' type='video/mp4'>Your browser does not support the video tag.</video>
</div>
</div>
<div>
</div>
</body>
<script type='text/javascript'>
<!--
//-->
</script>
3
Answers
Finally did it thanks to your help guys :)
You are having many silly mistakes in your code
eg :
<a href=javascript:HideAllShowOne( 'w11')>Back propagation Algorithm</a>
Corrected code :
<a href=javascript:HideAllShowOne('w11')>Back propagation Algorithm</a>
Lower-case w
.And two of your
w
invar IDvaluesOfEachDiv = "w11 W12 W21 w31"
areUpper-case
,W12
andW21
Note : ids are
case-sensitive
Remove double
href=
onWeek 2
andWeek 3
subli
You should not provide
#
before the id indiv
sEDIT : Provided a working snippet below
In addition to @Munawir’s answer, in
<div id='#w11' style='display:none;'>
element id is#w11
and notw11
. Remove#
from id.