I have following html<p class="get">This is some content.</p> what I would like to do is to make it like this:<p class="get">This is <span>some</span> content.</p>.
To accomplish this I know I should: 1. get my certain text (done that…)
2. Wrap my text in span (done that also…)
3. replace my text with text that contains my span (haven’t done it)
My problem is step 3 I just can’t figure it out. So how can I replace my “old” text with new one?
Thank you guys!!!
My code looks like this:
$(document).ready(function(){
//get the whole text
var ptext = $(".get").text().split(" ");
var myText = ptext[2];
//alert(ptext[2])
//alert(myText);
if($('.get').text().contains(myText)){
//$('<span>'+myText+'</span>').appendTo($('.get'));
}
else{
alert('no text');
}
});
1 Answer