I can not highlight a text with brackets instead of colors.

Joined
Jan 13, 2023
Messages
1
Reaction score
0
I want to highlight text with javascript, and it works succesful with colors, but I don't know how to do it with characters.
I attached a part of my code: the result I got(yellow highlight), and the result I want to get.
code.png


The result I got(yellow highlight), and the result I want to get:
result.png
 
Joined
Nov 13, 2020
Messages
302
Reaction score
38
You do not give enough information to answer this question. How do you know what 'this' is in this.style.background?
But if you can recover the text (the 'this') we can add █ in front and after the text
Code:
<body>
<p id="demo"> I will display text </p>

<script>
let text = document.getElementById("demo").innerHTML
document.getElementById("demo").innerHTML = '&block;' +text+'&block;';
</script>
</body>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top