Hey Itoh,
Welcome to the Wix Code forums.
I think this will work for you:
let text = $w("#text1"); // id of element must have # (hashtag)
console.log(text);
text.html = text.html.replace(/<a/g, '<a style="background-color:#aa7100;text-decoration:underline;"');
console.log(text.html);
I included console.log to make sure it was working.
Good luck,
Yisrael
Thanks for your help, but still have same trouble.
Also, it seems no trouble check with console output. but every links in actual page still have no links.
I tried the code out on a test page and it worked fine. Maybe you’re doing something slightly different. You’ll have to go over everthing carefully.
Good luck,
Yisrael
Hm…
btw, I paste your source for test, I got error about text.html(/<a/g,…) is not function. Is it little mistake? I mind it causes because I replaced it text.html.replace(/<a/g,…).
And I think it can replace Element array by for loop. Is it correct?
You are right - somehow replace got deleted from my code. I fixed my code above. Thanks
I’m confused about this!
$w.onReady(function () {
$w("#text1Post").html = $w("#text1Pre").html.replace(/<a/g, '<a style="background-color:#aa7100;text-decoration:underline;"');
// this makes good, but I don't says so.
let text = $w("#text2");
text.html = text.html.replace(/<a/g, '<a style="background-color:#aa7100;text-decoration:underline;"');
// this still can't get well.
});
Sorry, I don’t understand.
My example code above works just fine. I checked it. I don’t understand what you’re trying to do. But if it works for you then that’s great.
replace() is a Javascript function (not necessarily Wix Code). I don’t know why this isn’t working for you. I tried this with a href=“#” and it worked fine. You might need to check your code more carefully.
You might want to check this reference as well: JavaScript String replace() Method