简体   繁体   中英

jQuery Toggle Dropdown Menu

How could I write a section of jQuery so that when Trials is clicked that it will show the dropdown menu options:

Update:

jQuery(document).ready(function () {

    $("a[href='http://sheep.local/cms/trials']").click(function(e){
        e.preventDefault(); // In case you don't want the link to open...
        $(this).next('ul').slideToggle();
    });
});​

HTML:

       <div id="mainnavwrap">
            <div id="mainnav" class="clearfix">
    <ul class="menu">
    <li class="first current">
        <a href="http://sheep.local/cms/home">Home</a>
    </li>
    <li>
        <a href="http://sheep.local/cms/features">Features</a>
    </li>
    <li>
        <a href="http://sheep.local/cms/options">Options</a>
    </li>
    <li>
        <a href="http://sheep.local/cms/pumps-motors">Pumps & Motors</a>
    </li>
    <li>
        <a href="http://sheep.local/cms/shows">Shows</a>
    </li>
    <li>
        <a href="http://sheep.local/cms/trials">Trials</a>
        <ul>
            <li class="first">
                <a href="http://sheep.local/cms/trials/mathews-trial">Mathews Trial</a>
            </li>
            <li>
                <a href="http://sheep.local/cms/trials/novatis-trial">Novatis Trial</a>
            </li>
            <li>
                <a href="http://sheep.local/cms/trials/waimati-vet-trial">Waimati Vet Trial</a>
            </li>
            <li class="last">
                <a href="http://sheep.local/cms/trials/uk-scab-mite-trial">UK Scab Mite Trial</a>
            </li>
        </ul>
    </li>
    <li class="last">
        <a href="http://sheep.local/cms/contact">Contact</a>
    </li>

    </ul>
</div>
          </div> 

CSS:

#wrapper #contentarea #blue_box .centerblue_txt ul li ul{
    width:190px;
    padding:5px 0 0 10px;
    display:none;
}
#wrapper #contentarea #blue_box .centerblue_txt ul li ul li{
    width:185px;
    padding:5px 0 5px 5px;
    border-top:1px dotted #424242;
    border-bottom:0px;
}
#wrapper #contentarea #blue_box .centerblue_txt ul li ul li a,
#wrapper #contentarea #blue_box .centerblue_txt ul li ul li a{
    width:180px;
    padding:0 0 0 10px;
    font-size:12px;
    background:url(../img/liBullets.gif) no-repeat left 4px;
}
#wrapper #contentarea #blue_box .centerblue_txt ul li ul li#current a,
#wrapper #contentarea #blue_box .centerblue_txt ul li ul li a:hover{
    color:#D1D1D1;
    background:url(../img/liBullets.gif) no-repeat left 4px;
}
#wrapper #contentarea #blue_box .centerblue_txt ul li a:hover, 
#wrapper #contentarea #blue_box .centerblue_txt ul li a:active {
    background:#5490f3;
}

Take a look at this piece of code: http://jsfiddle.net/G9kda/6/ Click 'deelnemers' for the desired effect.

EDIT: I adjusted it to your code: http://jsfiddle.net/hXNnD/1/

You could use something like this (Only for Trials)

$("a[href='http://sheep.local/cms/trials']").click(function(e){
    e.preventDefault(); // In case you don't want the link to open...
    $(this).nextAll('ul').slideToggle();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM