jQuery Simple Collapsible Div?

前端 未结 4 1868
南笙
南笙 2021-01-31 17:57

I am looking for the proper, simple, small code to do the following things:

  • Click on Element with Class Applied to it.

  • DIV.CLASS - Which expands

4条回答
  •  一生所求
    2021-01-31 18:28

    I wanted to do this with multiple divs, each with their own trigger. Building on AlienWebguy's answer above:

    HTML

    more 1...

    more 2...

    Javascript

    $('.expand').click(function(){
        target_num = $(this).attr('id').split('-')[1];
        content_id = '#expandable-'.concat(target_num);
        $(content_id).slideToggle('fast');
    });
    

    CSS

    .expand {
        font-weight: bold;
        font-style: italic;
        font-size: 12px;
        cursor: pointer;
    }
    .expandable {
        display:none;
    }
    div {
        margin: 10px;
    }
    

    https://jsfiddle.net/Q4PUw/3767/

提交回复
热议问题