0

I have

<div class="col-xs-12">
  Congratulations! Here is your submitted post.
  <p class="post-details">Lorem ipsum</p>
</div>

How can i remove Congratulations! Here is your submitted post. ?

I tried few things like:

$(".post-details").each(function(){
    var text = $(".post-details").prev().text().remove();
    console.log(text);
});

But it doesn't catch that text.

Also tried this answer but it doesn't work https://stackoverflow.com/a/1571096/1018804

rob.m
  • 9,843
  • 19
  • 73
  • 162

3 Answers3

2

Check this:

https://stackoverflow.com/a/17852238/5089697

It filters the content inside any element and find the correct node you want to remove (in your case the text which is not wrapped in any element but it is a child to the div). Try it.

Momondo
  • 306
  • 1
  • 2
  • 10
0

You could put the text you want to delete inside a div element with an id and remove that div.

Like this:

<div class="col-xs-12">
<div id=“textToRemove”>Congratulations! Here is your submitted post.</div>
<p class="post-details">Lorem ipsum</p>
</div>

Then remove the div with jquery like so:

$("#textToRemove").remove();
thecoolwinter
  • 861
  • 7
  • 22
-1

here are what you want.

function Delete(){
$('#con').text('');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-xs-12">
<p id='con'>
  Congratulations! Here is your submitted post.
  </p>
  <p class post-details>Lorem ipsum</p>
</div>
<button onclick='Delete()'>Delete</button>