how to make a text object have different html properties so that the #hashtag is blue and the rest is black?
The content of the text comes from a collection, then when loading the data, the hashtag must appear already blue, or what is the best way to create a hashtag for my site?
I hope you can help me
My intention is that users who comment on my site can put their hashtag, send the comment and when the data is loaded the hashtag is ready, there must be a form so that in the code of the page it is changed to blue only the hashtag to load
You are amazing! that worked, although one more thing, I managed to change the font of the hashtag but I need all the text to be in “Helvetica”. How do I do it?
let value = itemData.post;
let arr = value.split(" ");
let html = “
”; for ( let i = 0; i < arr.length; i++) {
if (arr[i][0] === “#”) {
html += <span style="color: blue;font-family:helvetica;font-size:16px;">${arr[i]} </span>
} else {
html += (arr[i] + " ");
}
}
html += “
let value = itemData.post;
let arr = value.split(" ");
let html = "<p>"
for (let i = 0; i < arr.length; i++) {
if (arr[i][0] === "#") {
html += `<span style="color: #002B7D;font-family:helvetica;font-size:16px;">${arr[i]} </span>`
} else {
html += (arr[i] + " ");
}
}
html += "</p>"
$item('#post').html = html;
result:
This is the substitution you mentioned to add a link to the hashtag:
let value = itemData.post;
let arr = value.split(" ");
let html = "<p>"
for (let i = 0; i < arr.length; i++) {
let site = 'https://www.mysite.com.mx/' + arr[i].slice(1, arr[i].length)
if (arr[i][0] === "#") {
html += '<span style="color: blue"><a href="'+site+'</a></span>'
} else {
html += (arr[i] + " ");
}
}
html += "</p>"
$item('#post').html = html;
result:
due to how it appears try to modify it like this:
let value = itemData.post;
let arr = value.split(" ");
let html = "<p>"
for (let i = 0; i < arr.length; i++) {
if (arr[i][0] === "#") {
let site = 'https://www.mysite.com.mx/' + arr[i].slice(1, arr[i].length)
html += '<span style="color: blue">' + '<a href=' + site + '</a></span>'
} else {
html += (arr[i] + " ");
}
}
html += "</p>"
$item('#post').html = html;
result:
What am I doing wrong? why did the hashtag disappear?
html += '<span style="color: blue">' + arr[i] + '<a href=' + site + '></span>'
Result
Now the hashtag has the corresponding link, however a space has disappeared between example#words => example #words now I must recover that " " that has been lost
let value = itemData.post;
let arr = value.split(" ");
let html = "<p>"
for (let i = 0; i < arr.length; i++) {
let site = 'http://mywebsite.com/'+arr[i].slice(1, arr[i].length)
if (arr[i][0] === "#") {
html += '<span style="color: blue">' + arr[i] + '<a href=' + site + '></span>';
} else {
html += (arr[i] + " ");
}
}
html += "</p>"
$item('#post').html = html;
}
Criamos um banco de dados com conteúdo gerado pelo usuário e exibimos em um repetidor em nossa pagina feed. Como eu posso aplicar este codigo para transformar as palavras digitatadas com “h” em hashtags?