$(document).ready(function(){
$("#btn1").click(function(){
var deger1 = $('#txt1').val();
$("p").append(deger1 + "<br>");
});
$("#btn2").click(function(){
var word = $('#txt2').val();
if(word === null){
break;
}
else{
var rgx = new RegExp('\\b('+word+')\\b', 'ig');
$('p, p *').contents().filter(function() {
return this.nodeType === 3;
}).each(function() {
$(this).replaceWith($(this).text().replace(rgx, '<span class="selected">$1</span>'));
});
}
});
});