English 中文(简体)
改称职称
原标题:change classname not work with nextSibling

我的法典如下:

<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>

<style type="text/css">
.easy-archives .closed {
display:none;
}
</style>

It work with tag when nextSibling is not work Somebody help me, please. Sorry my english not very well.

最佳回答

基本上,你想在四级=“月”下带ul子

为此,

var parent = button.parentNode.parentNode; //get the div class="month"
var dailyArchives = parent.getElementsByTagName( ul ).item(0); //get the ul class="open"

问题回答

暂无回答




相关问题
Jquery toggling each and every div with same id

I want to toggle a bunch of divs that each have the same id. My current jquery code only toggles one div. (I ve tried using a mixture of .next and .parent.next, but haven t found anything yet) $( #...

checkbox / div toggle

$(".trigger").click(function () { $(this).next(".toggle").slideToggle("fast"); $(this).toggleClass("active"); return false }); HTML: <input type="checkbox" class="trigger"> <div class=...

jQuery toggle effects flashing entire page in certain cases

I have a page that may have 10 or so editable panels of information. To enable editing, I create a new DIV, load content via AJAX then toggle the divs (the one showing toggles off and the one I ...

jquery: .toggle(switch) with effect?

i like the jquery.toggle(switch) function as i can do the following in one line; $( .mytable ).toggle(checkboxes[0].checked); However i cant seem to integrate effects into this call (sliding / ...

How to correct a jQuery syntax error?

I m trying to update a Total: (span.wrap p span) field at the bottom of a form using jQuery. I have a few checkboxes, each of which has an associated price contained within the title attribute like ...

热门标签