javascript - How to replace all instances of <p><br></p> with an empty string using jquery? -


i want grab html content , store in variable. want clean content replacing instances of <p><br></p> empty string

this might you

$('p').each(function(){    console.log($(this).text());     $(this).remove();  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div>    testing  </div>  <p>test 1</p>  <p>test 2</p>

for grab html element, please use element tag, classname or id, here i've used element tag.

instead of storing variable, i've done console.log.

for cleaning content empty string, can use empty method in javascript $(this).empty, clear content not element. so, i've used remove method remove element.

hope you.


Comments