开发者

How to replace '<p>' with '<li>' in an array in jQuery?

开发者 https://www.devze.com 2022-12-25 05:31 出处:网络
Let\'s say I have this $(document).ready(function() { var array = $.makeArray($(\'p\')); $(array).appendTo(document.body);

Let's say I have this

$(document).ready(function() {
   var array = $.makeArray($('p'));
   $(array).appendTo(document.body);
   });
});

<p>how</p>
<p>are</p>
<p>you</p>
<p>baby?</p>

If I want to replace <p> 开发者_如何学运维with <li> and expected output is ...

<li>how</li>
<li>are</li>
<li>you</li>
<li>baby?</li>

What should I do? Thanks in advance!


$("p").each(function () {
     $(this).replaceWith("<li>" + $(this).html() + "</li>");
});


Here is a quick and dirty solution, but if you give me more details as far as what you are trying to do we might be able to come up with a better one.

$('p').each(function(){$(this).replaceWith('<li>'+$(this).html()+'</li>')})
0

精彩评论

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