mercredi 13 février 2019

How to replace a string on HTML webpage with another string using javascript?

I need to change one string with another using JavaScript for an HTML website. So, the "AuthorList" has a nodeList with the string "Test String". I need to change all occurrences of "test string" into "new test".

I have tried a lot of different modifications of the code below. I cant seem to figure out another way without getting errors.

for(var i=0, num=AuthorList.length; i<num; i++){
  if(AuthorList[i] = "Test String")
  {
    string.replace("New Test")
  }
}

After replacing the text, I also need a way to add styles to the new string. Is there a way to do that while also changing the string?

Aucun commentaire:

Enregistrer un commentaire