开发者

define actions for li item

I wont to perform action for the clicked li, as for expample toggle the nested ul

this is the html

<script type="text/javascript">
$(function() {
    $('#verticalfade').verticalfade();
});
</script>
<div id="verticalfade_container">
    <ul id="verticalfade">
        <li>Le Collezioni
            <ul>
                <li>Link 1</li>
                <li>Link 2</li>
            </ul>
        </li>
        <li>Extra Plus
            <ul>
                <li>Link 1</li>
                <li>Link 2</li>
            </ul>
        </li>
    </ul>
</div>

This is the javascript:

(function($){
    $.fn.extend( {
        verticalfade开发者_高级运维: function(options){

            var defaults = {
                speed: 'normal'
            };
            var options = $.extend(defaults, options);


            $('ul#verticalfade li ul').each(function(){
                $('ul#verticalfade li ul').hide();
            });    

            $('ul#verticalfade li').each(function(){
                $(this).click(function(){
                    $(this).next('ul').toggle(500);
                });
        });
        }    
    });
})(jQuery);

i hide all the sub ul in the list but i cannot define a function for each li to show the next ul only. i tried the next('ul') function but i can only toggle all the ul at once.


change $(this).next('ul').toggle(500); to

//first line hides the previously clicked li's children $(this).siblings('li').children('ul').slideUp(); $(this).children('ul').toggle(500);


Here's a simple variant (full source at http://gist.github.com/575089):

In essence:

$('ul#verticalfade > li > ul').each(function(){
        $(this).hide();
    });    

$("ul#verticalfade > li").click(function(){
    $("ul", this).toggle(500);
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜