I'm trying to delete a string from a textarea using jQuery once.
However, every time i run my code, I get the following error and nothing gets deleted from the textarea at all:
Error: Syntax error, unrecognized expression: <span data-price="5.99" data-name="Stamina" class="pricetag">Stamina</span>
To explain this better, I created this FIDDLE
If you click on the texts under the textarea, it should remove the string in the textarea but nothing happens.
This is my current code:
$(document).one('click', '.pricetag',function(){
$("#Finalized").contains('<span data-price="5.99" data-name="Stamina" class="pricetag">Stamina</span>').remove();
});
Could someone please advise on this issue?
EDIT:
I tried this and still doesn't delete anything from the textarea:
$(document).one('click', '.pricetag',function(){
// $("#Finalized").contains('<span data-price="5.99" data-name="Stamina" class="pricetag">Stamina</span>').remove();
$('#Finalized').filter(function() {
return $(this).html().indexOf('<span data-price="5.99" data-name="Stamina" class="pricetag">Stamina</span>') != -1;
}).remove();
});