// text I will obtained from database
textToClear = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the \"1500s\", when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
textAfterClear = ""
parseTextToWords();
function parseTextToWords(){
// basic interpunct chars should be single elements to click
textToClear = textToClear.replace(/\./g, ' .');
textToClear = textToClear.replace(/\?/g, ' ?');
textToClear = textToClear.replace(/\!/g, ' !');
textToClear = textToClear.replace(/\,/g, ' ,');
textToClear = textToClear.replace(/\"/g, ' " ');
// removing multiple spaces for single
textToClear = textToClear.replace(/ +(?= )/g,'');
var words = textToClear.split(" ");
// generate words with ids to change their future css
for ( var i = 0, l = words.length; i < l; i++ ) {
var word = $('<span />').attr({'id':'word'+i }).html(" "+words[i]);
word.css('color','black');
$('.clearText').append(word);
$('#word'+i).click(function() {
if($(this).css('color') == "rgb(0, 0, 0)"){
$(this).css('color','red');
}else{
$(this).css('color','black');
}
});
}
}
function removeSelected(){
$('.clearText').find('*').each(function() {
if($(this).css('color') == "rgb(0, 0, 0)"){
textAfterClear += $(this).html();
}
});
$(".clearText").html(textAfterClear);
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<title>Word chooser</title>
</head>
<body>
<div class="clearText" style="border: 1px solid darkorange;" >
</div>
<div align="center"><button onclick="removeSelected()" type="submit">Delete Choosed</button></div>
</body>
</html>