2

HERE IS PSEUDO CODE

var content = $('.getcontent').html();
print content
"<p>one</p>
<li>1</li>
<li>2</li>
<a>ok<a><br>1"
 replace.content(li with p)

output:

print content 
  "<p>one</p>
    <p>1</p>
    <p>2</p>
    <a>ok</a><br>1"

How can i do that to get my results?

2
  • 1
    try searching before posting, you can get the basic idea here:: stackoverflow.com/questions/2543617/… Commented Jul 22, 2014 at 4:08
  • other tags are also present here? Will it work Commented Jul 22, 2014 at 4:16

1 Answer 1

2

Try to use .replaceWith() along with its receiver function to accomplish your task,

$('.getcontent').find('li').replaceWith(function(_,content){
  return '<p>' + content + '</p>';
});

DEMO

Note: I am not fully aware of your context, Anyway this code would make an invalid HTML.

Sign up to request clarification or add additional context in comments.

2 Comments

what about the other tags? <a> <br>
@SomPathak Hey, you did not mention that in the question initially..? Just now you added the additional informations.. Anyway your new html structure wont cause any odd behaviors. since we have selected the li elements particularly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.