homepage Welcome to WebmasterWorld Guest from 54.167.173.250
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

    
change classname not work with nextSibling
quangnh87




msg:4293550
 4:18 am on Apr 7, 2011 (gmt 0)

My code is follows:

<div class="sidebar" id="southsidebar">

<!-- archives -->
<div class="widget">
<h3>Archives</h3>
<div class="easy-archives">
<div class="monthly-archives">
<div class="month">
<div class="title">
<a onclick="toggle(this);" href="javascript:void(0);" class="open-button">toggle</a>
<a title="Show detailed results for February 2011 " href="#" class="detail">February 2011 </a>
<em>(2 posts)</em>
<div class="fixed"></div>
</div>

<ul class="open">
<li>08: <a title="View this post 1" href="#">Post 1</a><em>(0 comments)</em></li>
<li>03: <a title="View this post 2" href="#">Post 2</a><em>(5 comments)</em></li>
</ul>
</div>
</div>
</div>

<div class="easy-archives">
<div class="monthly-archives">
<div class="month">
<div class="title">
<a onclick="toggle(this);" href="javascript:void(0);" class="open-button">toggle</a>
<a title="Show detailed results for September 2008" href="#" class="detail">September 2008</a>
<em>(1 posts)</em>
<div class="fixed"></div>
</div>

<ul class="open">
<li>27: <a title="View this post 1"href="#">Post 1</a><em>(277 comments)</em></li>
</ul>
</div>
</div>
</div>
</div>

</div>

<script type="text/javascript">
function toggle(button) {
if (button.className == "open-button") {
button.className = "closed-button";
} else {
button.className = "open-button";
}

var parent = button.parentNode;
var dailyArchives = parent.nextSibling;
if (dailyArchives.className == "open") {
dailyArchives.className = "closed";
} else {
dailyArchives.className = "open";
}
}
</script>

It work with tag <a class="open-button" .../> when nextSibling is not work
Somebody help me, please. Sorry my english not very well.

 

JAB Creations




msg:4294716
 6:49 pm on Apr 9, 2011 (gmt 0)

When you call toggle(button) you'll have to send a specific object already created (e.g. )document.getElementById('element_id_here'). Therefore try alerting (e.g. alert(button); and alert(typeof button)) in the first line of that function.

Also Opera is excellent for debugging JavaScript and unfortunately for some reason Firefox hides a few JavaScript errors that don't make it past Opera for some reason.

Good job for opting to use the DOM. :)

- John

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved