Reputation: 107
After page is done loading, I would like script to add tags to certain parts of the text within it. For example:
<p> Some text is here. The page has already finished loading</p>
to
<p> Some text is <b class="bolded">here</b>. The page has already finished loading</p>
Upvotes: 0
Views: 53
Reputation: 545
Maybe u can do something like $("p") or add an ID at your <p>
example:
<p id='testing1'> Some text is here. The page has already finished loading</p>
then when after the string render and you may use the script as below to replace it:
var strTest = $("#testing1").html();
strTest = strTest.replace("here",'<b class="bolded" style="font-weight:bold;">here</b>');
console.log('strTest:',strTest);
Upvotes: 0
Reputation: 619
You can do this by calling a function onload of page. Give the ID to the elements of HTML and write the below code
HTML :
<p id='testing1'> Some text is here. The page has already finished loading</p>
Javascript:
function onLoad()
{
var strTest = $("#testing1").html();
strTest = strTest.replace("here",'<b class="bolded" style="font-weight:bold;">here</b>');
console.log('strTest:',strTest);
}
Upvotes: 1