Reputation: 345
i have domain in my html page, that appears in several locations (in link, src, title, etc)
i need to change the domain name, for example instead of "Yahoo.com", to become "Morad.com" on the page load.
<title>yahoo.com</title>
<script src="yahoo.com"></script>
<href>yahoo.com</href>
so my request, it's does not matter where this domain exist i need to replace it.
so i write this:
$(document).ready(function(){
var link = document.replace('Yahoo.com','Morad.com');
)};
but that does not help. can you please advise
Upvotes: 0
Views: 50
Reputation: 561
There are better ways also.
const blackList = [
'script',
'html',
'body',
'meta',
];
const elements = document.querySelectorAll(`*:not(${blackList.join(', ')})`);
function changeText(elms, text, replaceText) {
text = new RegExp(text, 'gi');
elms.forEach(elm => {
if (text.test(elm.innerText)) {
elm.innerText = replaceText;
}
});
}
changeText(elements, 'yahoo.com', 'Morad.com')
Upvotes: 1