ben
ben

Reputation: 671

How to remove an element with jquery from a variable containing HTML

I am making a forum were users can quote other people's comments.
When you click quote on a comment, it gets the html of that comment and puts it into a little box which says Quote: Original post by a member, like most forums do.

However, when I reply to a comment containing a quote, it returns

Quote: Original post by a member
      Quote: Original post by a member

So when I post the next reply, it has two quotes piled on top of each other.
What I would like to do is remove the quote from the original comment so that only 1 quote is ever shown. The ID of the quote is span.threadreply and i can remove it from the DOM using the below code.

$("#somereplyid span.threadreply").remove()

But this removes it from the page, which I don't want to do. I have the HTML of somereplyid in a variable labeled reply. How using jQuery can i sanitize this variable to remove span.threadreply without removing it from the actual document?

If I was unclear in anyway please tell me so I can edit and improve the question.

Upvotes: 3

Views: 1558

Answers (1)

Sergio
Sergio

Reputation: 28845

Try using this to define your reply variable:

var reply = $('#reply').clone().find('span.threadreply').remove().end().html();

Upvotes: 3

Related Questions