Wrap multiple div elements on same class

前端 未结 5 931
执笔经年
执笔经年 2020-12-11 04:48

I would like to use jQuery to wrap sets of class elements in a div but can\'t find the solution.

HTML:

5条回答
  •  借酒劲吻你
    2020-12-11 05:14

    Use wrapAll() method

    $(function(){
        var classes = ['.first', '.second', '.third'];
    
        for (i = 0; i < classes.length; i++) {
            $(classes[i]).wrapAll('
    '); }​ });

    Demo: http://jsfiddle.net/g9G85/

提交回复
热议问题