0

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>

2 Answers 2

1

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);
  }
Sign up to request clarification or add additional context in comments.

Comments

0

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.