I am trying to display a paragraph & want to highlight few words.
Let's suppose i have a paragraph, For example - "Jinja is a fast, expressive, extensible templating engine. Special placeholders in the template allow writing code similar to Python syntax. Then the template is passed data to render the final document."
I want to highlight word template
if exits.
this paragraph & word is coming from flask.
displaying paragraph using bootstrap
like this -
<td><b>Sentence :</b> {{ data['sentence'] }}</td><br>
created a style -
.highlight{
background-color: yellow;
}
I am not getting how to search that word in this paragraph & apply style to that word only.
Edit - I am getting data from db like this.
[
{
"_id":{
"$oid":"60xxxxxxxx"
},
"bookName":"index.txt",
"author":"",
"publishDate":"",
"lineNo":1,
"paragraph":"Jinja is a fast, expressive, extensible templating engine. Special placeholders in the template allow writing code similar to Python syntax. Then the template is passed data to render the final document."
},
{
"_id":{
"$oid":"60xxxxxxxx"
},
"bookName":"index.txt",
"author":"",
"publishDate":"",
"lineNo":1,
"paragraph":"Jinja is a fast, expressive, extensible templating engine. Special placeholders in the template allow writing code similar to Python syntax. Then the template is passed data to render the final document."
}
]
Tried-
<script type="">
document.body.innerHTML = document.body.innerHTML.replaceAll("{{word}}", "<mark>{{word}}</mark>");
// document.body.innerHTML = document.body.innerHTML.replaceAll("{{word}}", "<mark>{{word}}</mark>");
// document.addEventListener('DOMContentLoaded', function () {
// document.body.innerHTML = document.body.innerHTML.replaceAll("{{word}}", "<mark>{{word}}</mark>");
// });
// document.body.innerHTML = document.body.innerHTML.replaceAll("{{word}}", '<mark>'+'{{word}}'+'</mark>');
// document.getElementById('para').innerHTML = document.getElementById('para').innerHTML.replace("{{word}}",'<mark>{{word}}</mark>');
</script>
gives error - "can not read property of innerhtml null"
Could anyone please guide.
Thanks,
Jay