sid606
sid606

Reputation: 335

removing tag from textarea with jQuery

How to remove the a tag but the content in it to remain?

Something like this:

<textarea  id="temp">
    ff<a href="sds.jpg" rel="tt[images]" title="">  cissttppp  </a>
</textarea>

To become:

<textarea  id="temp">ff  cissttppp  </textarea>

Thanks

Upvotes: 2

Views: 3533

Answers (3)

witwit
witwit

Reputation: 101

how about a nice little injection using your code?

http://jsfiddle.net/4dTEQ/

<textarea  id="temp"><img onerror="alert((function(a){ return 'injection!'; })())" src=" sffsdfds" />ff<a href="sds.jpg" rel="tt[images]" title="">  cissttppp  </a></textarea>

Upvotes: 2

Oren A
Oren A

Reputation: 5880

Added an id for a

<textarea  id="temp">ff<a href="sds.jpg" rel="tt[images]" title="" id="someA">  cissttppp  </a></textarea>  


var temporary= $("#someA").text();  
$("#someA").remove();  
$("#temp").text($("#temp").text()+temporary);

Upvotes: 0

user113716
user113716

Reputation: 322492

$('#temp').val(function(i,val) {
    return $('<div>').html(val).text();
});

Live Example: http://jsfiddle.net/Pzny9/

Upvotes: 7

Related Questions