Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9163691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:30:23+00:00 2026-06-17T14:30:23+00:00

This code is attempting to highlight (by adding ‘bold’ tag) some characters that are

  • 0

This code is attempting to highlight (by adding ‘bold’ tag) some characters that are in the HTML body. (These are specified in the JS function)
But instead of the text becoming bold, I get the ‘bold’ tag as the result in the html page that is getting rendered.

While I want some thing like

This is a test message

I get

This is a test <b>message</>

Any help would be awesome.

    <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Test</title>

<script>

function myFunction(){
        var children = document.body.childNodes;
    for(var len = children.length, child=0; child<len; child++){
     if (children[child].nodeType === 3){ // textnode
        var highLight = new Array('abcd', 'edge', 'rss feeds');
        var contents = children[child].nodeValue;
        var output = contents;
        for(var i =0;i<highLight.length;i++){
            output = delimiter(output, highLight[i]); 
        }


    children[child].nodeValue= output; 
    }
    }
}

function delimiter(input, value) {
    return unescape(input.replace(new RegExp('(\\b)(' + value + ')(\\b)','ig'), '$1<b>$2</b>$3'));
}
</script>



</head>
<body>
<img src="http://some.web.site/image.jpg" title="abcd"/>

These words are highlighted: knorex, edge, rss feeds while these words are not: knewedge, abcdef, rss feedssss

<input type ="button" value="Button" onclick = "myFunction()">
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:30:24+00:00Added an answer on June 17, 2026 at 2:30 pm

    The problem is that you are putting HTML in to a text node, so it is being evaluated strictly as text. One easy fix would be to simply operate on the innerHTML of the body element, like this:

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
    <title>Test</title>
    
    <script>
    
    function myFunction(){
      var highLight = ['abcd', 'edge', 'rss feeds'],
          contents = document.body.innerHTML;
    
      for( i = 0; i < highLight.length; i++ ){
        contents = delimiter(contents, highLight[i]); 
      }
    
      document.body.innerHTML = contents;
    }
    
    function delimiter(input, value) {
      return input.replace(new RegExp('(\\b)(' + value + ')(\\b)','ig'), '$1<b>$2</b>$3');
    }
    </script>
    
    
    
    </head>
    <body>
    <img src="http://some.web.site/image.jpg" title="abcd"/>
    
    These words are highlighted: knorex, edge, rss feeds while these words are not: knewedge, abcdef, rss feedssss
    
    <input type ="button" value="Button" onclick = "myFunction()">
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to use code I've found that uses Win32. However, I'm getting this
I have this code here that is attempting to work out if a point
I am attempting to interop to this simple scala code, but am having some
I am attempting to implement this code https://gist.github.com/1859653 that allows sqlalchemy to interact with
I am attempting to build a simple Where clause. This is the code that
Hi I have been working on this code today after attempting some of the
How do I remove the reflection warning from this Clojure code that is attempting
This code is the core of a much larger script that works great in
This code fails on some machines: // Parse error: syntax error, unexpected '[' ...
Consider this code attempting to create an Active Directory account. It's generating an exception

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.