Once again, I'm feeling a bit lost on where to go with this coding issue. It seems quite basic, but I'm struggling to pinpoint the problem. My goal is to hide several IDs, and while it does work, I keep encountering an error: Uncaught TypeError: Cannot read property 'style' of null. This error only shows up on pages where the function isn't present...
function new1()
{
var news = ["1", "2", "3", "4"];
for (var i = 0; i < news.length; i++)
{
var s = document.getElementById("news" + news[i]).style.display = "none";
}
}
Thank you in advance. I can provide the XHTML if necessary. It consists of several divs named news1, news2, etc. My main concern is that this error is interfering with other scripts from functioning properly.
<a onclick="show1()" href="#"><h3>New Song Premiere by Spice Girls</h3></a><div id="news1">
<p class="news" > <em>"Headlines (Friendship Never Ends)"</em> is the first single from the reformed girl band since 2000 and serves as the official Children In Need track for 2007.</p>
<p class="news">Geri Halliwell, Victoria Beckham, Melanie Brown, Melanie Chisholm, and Emma Bunton have reunited to promote a new Spice Girls' greatest hits album and an upcoming world tour. <a href="#">Read more ...</a></p></div>
</div>
<div id="story2">
<a onclick="show2()" href="#"><h3>Jay-Z's Defense of Nas' Album Title</h3></a><div id="news2">
<p class="news">Hip-hop mogul Jay-Z has defended Nas' decision to name his new album <span>N**ger</span>, but he believes the naming was "misguided".</p>
<p class="news">Jay-Z, real name Shawn Carter, is releasing the LP under his label Island Def Jam Music Group, despite not being a fan of its title. <a href="#">Read more ...</a></p></div>
</div>
<div id="story3">
<a onclick="show3()" href="#"><h3>Amy Winehouse's MTV EMAs Performance Defense</h3></a><div id="new3">
<p class="news" id="news3">Amy Winehouse has spoken out in defense of her performance at Thursday's MTV European Music Awards, citing exhaustion for her unusual behavior. <a href="#">Read more ...</a></p></div>