Wrap a span around some text in jQuery

后端 未结 3 799
孤城傲影
孤城傲影 2021-01-18 18:45

What I have :

  • My text
    • blahblahblah
3条回答
  •  春和景丽
    2021-01-18 19:24

    Try:

    $('#myId > li').each(
        function(){
            $(this.firstChild).wrap('');
        });
    

    JS Fiddle demo.

    With regards to wanting to add the class to the ul:

    $('#myId > li').each(
        function(){
            $(this.firstChild).wrap('');
            $(this).find('ul').addClass('myClass');
        });
    

    JS Fiddle demo.

提交回复
热议问题