锚定点击时嵌套的ul显示

时间:2014-12-18 09:47:31

标签: javascript jquery html

我的网站结构如下:

当我点击" add-info" ul没有显示,不太清楚如何处理才能显示它?

<ul>
    <li>Liebherr LHM 600 Mobile Harbour Crane. <a class="add-info" href="#">Find out more</a>
        <ul class="hidden-list">
            <li>Liebherr LHM 600 Mobile Harbour Crane. SWL of 208 Ton and capable of lifting 53.7 ton at 58 meters radius. Can be used for bulk container loading/unloading with our Bromma container handler attachment. Maximum hoisting height above quay of 59 metres.</li>
        </ul>
    </li>
    <li>Liebherr LR1300 Crawler Crane. <a class="add-info" href="#">Find out more</a>
        <ul class="hidden-list">
            <li>Coming December 2014 Liebherr LR1300 Crawler Crane. Can be configured to lift 300.5 ton and can be configured to a maximum radius of 80 metres. Can be fitted with a leader rig attachment and Bruce 16 ton piling hammer for piling.</li>
        </ul>
    </li>
    <li>Sennebogen 6130 Crawler Crane. <a class="add-info" href="#">Find out more</a>
        <ul class="hidden-list">
            <li>Sennebogen 6130 Crawler Crane. Can be configured to lift 136 ton and has a maximum radius of 42 metres.</li>
        </ul>
    </li>
    <li>Zoomlion RT55 Rough Terrain Crane. <a class="add-info" href="#">Find out more</a>
        <ul class="hidden-list">
            <li>RT55 Rough Terrain Crane. SWL of 54.88 ton and a maximum working radius radius of 41 metres. A main jib head height of 34 metres but also comes complete with a telescopic fly jib that can increase the head height up to a height of 54 metres and can be offset from 0 to 40 degrees.</li>
        </ul>
    </li>
    <li>Scheuerle 6 axel SPMT modular trailers complete with Z350 power pack units. <a class="add-info" href="#">Find out more</a>
        <ul class="hidden-list">
            <li>Scheuerle 6 axel SPMT modular trailers complete with Z350 power pack units. With a SWL of 48 ton per axel can be supplied in a vast array of different configurations.</li>
        </ul>
    </li>
    <li>Forklifts <a class="add-info" href="#">Find out more</a>
        <ul class="hidden-list">
            <li>Various sizes of forklifts available from 2.5 ton up to 32 ton.</li>
        </ul>
    </li>
</ul>

我想做的是&#34; add-info&#34;点击jQuery,显示ul.hidden-list,SlideDown或任何效果,只要它显示。

我创建了jsFiddle

我目前的jQuery代码:

$('.add-info').click(function() {

    $(this).children('ul.hidden-list').slideToggle();

    return false;
});

1 个答案:

答案 0 :(得分:2)

根据您的标记<ul>元素被放置为<a>的下一个元素,而不是直接后代,因此应使用.next()(或.siblings)方法:

$('.add-info').click(function() {
    $(this).next('ul.hidden-list').slideToggle();

    return false;
});

DEMO: http://jsfiddle.net/vog8bsLc/1/

相关问题