I wanted to replace match text to html link in content area in each post on WordPress site.
I implemented that by JavaScript as follows.
jQuery(document).ready(function(){
var selector = `article p` ;
for (i = 0; i < document.querySelectorAll( selector ).length; i++){
if ( document.querySelectorAll( selector )[i].innerText.match(/(vpn|VPN)/) !== null ){
var term = document.querySelectorAll( selector )[i].innerText.match(/(vpn|VPN)/)[1]
document.querySelectorAll( selector )[i].innerHTML = document.querySelectorAll( selector )[i].innerHTML.replace( term ,`<a href="https://yuis-programming.com/vpn">${term}</a>`)
break
}
}
});
As you can see the one replace plain HTML text with p
tag for hyperlink with dofollow.
So, this is my question. Does such JavaScript work correctly for SEO?