How to replace '<p>' with '<li>' in an array in jQuery?
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>')})
精彩评论