質問

私はjQueryを使って)(トグルを使用していると私は私のページのサイドバーがあり、各ヘッダは、

であります
<h2 class="sidebar-header">

私のコードの1つのセクションは次のようになります

    <div class="sidebar-section">   
        <h2 class="sidebar-header">SUBSCRIBE</h2>
        <p class="sidebar">Make sure you subscribe to stay in touch with the latest articles and tutorials. Click on one of the images below:</p>
        <div class="rss-icons">
            <a href="http://fusion.google.com/add?feedurl=http://feeds.feedburner.com/ryancoughlin"><img src="http://gmodules.com/ig/images/plus_google.gif" width="62" height="17" alt="Add to Google Reader or Homepage" class="feed-image"/></a> 
            <a href="http://add.my.yahoo.com/rss?url=http://feeds.feedburner.com/ryancoughlin" title="Web/Graphic Design/Development by Ryan Coughlin"><img src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo3.gif" alt="Add feed to My Yahoo" width="62" height="17" class="feed-image" /></a>
            <a href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http://feeds.feedburner.com/ryancoughlin" title="Web/Graphic Design/Development by Ryan Coughlin"><img src="http://www.newsgator.com/images/ngsub1.gif" alt="Subscribe in NewsGator Online" class="feed-image" height="17" /></a>
        </div>
        <hr />
        <p class="sidebar feed">Don't have those? Grab the <a href="http://feeds.feedburner.com/ryancoughlin" target="_blank" title="Subscribe to this feed">RSS</a> url.</p>
        <p class="sidebar delicious">Make sure you add me to <a href="http://del.icio.us/post?url=http://www.ryancoughlin.com&amp;title=Ryan Coughlin - Web/Graphic Design and Development" target="_blank" title="Add to delicious!">delicious!</a> </p>
    </div>

これらは、それぞれ、それらのDIV要素に包まれています。私はあなたがヘッダーをクリックした場合、それはコンテンツを縮小するためにそれを作るしようとしています。私は、トグルがあることを行うことができます知っているが、私はそれぞれの「サイドバーのヘッダー」のためにそれを作る場合は、ページ上の任意の一つの要素をクリックしますと、それはそれらをすべて非表示になります、私はこれをどのように行うことができますか?

役に立ちましたか?

解決

これを試してみてください。 nextAllする

    $(".sidebar-header").click(function() {
        $(this).nextAll().toggle();
    });

他のヒント

このような何かを試してみてください。

次のコードがあるとします:

<div class="topdiv">
    <h2 class="header">Header 1</h2>
    <div class="somecontent">
        This is the content
    </div>
</div>

<div class="topdiv">
    <h2 class="header">Header 2</h2>
    <div class="somecontent">
        This is the content
    </div>
</div>

さて、あなたはヘッダをクリックしたときに、そのヘッダの内容が表示/非表示になっていることを言ってます:

$(".header").click(function () {
    $(this).parent(".topdiv:first").find(".somecontent").toggle();
});

このようにして、特定のヘッダのコンテンツのみが残りをトグルし、しないであろう。

今、あなたは私があなたのために書かれているコードを解析し、あなた自身のコンテキストでそれを適用することができます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top