[英]Select an specific text fragment in a HTML and add bold font with javascript
I want to add a bold font in an specific text fragment in a HTML.我想在 HTML 的特定文本片段中添加粗体字体。 Where it says (10,90% TAE)* in the image.它在图像中说 (10,90% TAE)* 的地方。
The problem is that I have to inject it with Adobe target using javascript and this whole text numbers changes dynamically with javascript.问题是我必须使用 javascript 将它注入 Adobe 目标,并且整个文本数字随 javascript 动态变化。
The original code is:原代码是:
<p class="small clr-gray summary-interest" ing-unmask=""><span class="clr-black">10,39 % TIN</span> (10,90 % TAE)*</p>
And I want to bold (10,90% TAE)* like this with javascript:我想用 javascript 像这样加粗 (10,90% TAE)*:
<p class="small clr-gray summary-interest" ing-unmask=""><span class="clr-black">10,39 % TIN</span> <b>(10,90 % TAE)*<b></p>
I tried using the split method and select the part I want to bold but I dont know how to add it right:我尝试使用 split 方法并选择要加粗的部分,但我不知道如何正确添加:
"TIN": “锡”:
var startN = document.querySelector("#summary-region > div > div > div:nth-child(2) > div:nth-child(2) > p.small.clr-gray.summary-interest").innerHTML.split(" ")[3];
"TAE)*": "TAE)*":
var finishN = document.querySelector("#summary-region > div > div > div:nth-child(2) > div:nth-child(2) > p.small.clr-gray.summary-interest").innerHTML.split(" ")[6];
The whole text is:全文如下:
textocompleto = document.querySelector("#summary-region > div > div > div:nth-child(2) > div:nth-child(2) > p.small.clr-gray.summary-interest");
I guess I have to use the .innerHTML
but I dont know how to use it right.我想我必须使用.innerHTML
但我不知道如何正确使用它。 Anyone can help me?任何人都可以帮助我吗?
Doing this with JavaScript would look something like this:使用 JavaScript 执行此操作将如下所示:
const node = document.querySelector('p.summary-interest'); const span = document.querySelector('p.summary-interest span'); const text = node.childNodes[1].textContent; newHTML = `${span.innerHTML}<b>${text}</b>`; node.innerHTML = newHTML;
<p class="small clr-gray summary-interest" ing-unmask=""><span class="clr-black">10,39 % TIN</span> (10,90 % TAE)*</p>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.