Q:

Select specifics characters with jquery

I would like tu select the specifics characters cm in a specific div and add this in a span.
The html :
<div class="fc_img_tooltip_desc" style="line-height:1em;">20X10cm
10X100
50X50
100X100</div>

Jquery
<script>
function highlight_words(cm , fc_img_tooltip_desc) {
if(keywords) {
    var textNodes;
    keywords = keywords.replace(/\W/g, '');
    var str = keywords.split(" ");
    $(str).each(function() {
        var term = this;
        var textNodes = $(element).contents().filter(function() { return 
this.nodeType === 3 });
        textNodes.each(function() {
          var content = $(this).text();
          var regex = new RegExp(term, "gi");
          content = content.replace(regex, '<span class="highlight">' + term 
+ '</span>');
          $(this).replaceWith(content);
        });
    });
}
}
$(window).onload(function(){ highlight_words(); });
</script>

This don't work, i do something wrong.
What i have :
<div class="fc_img_tooltip_desc" style="line-height:1em;">20X10cm
10X100cm
50X50cm
100X100cm</div>

What i want:
<div class="fc_img_tooltip_desc" style="line-height:1em;">20X10 cm
10X100 cm
50X50 cm
100X100 cm</div>

A:

Select HTML element with querySelector() then do a replacement on textContent property:

var el = document.querySelector('.fc_img_tooltip_desc');
el.textContent = el.textContent.replace(/\Bcm/, function(match){
  return ' ' + match; 
})
<div class="fc_img_tooltip_desc" style="line-height:1em;">20X10cm
10X100
50X50
100X100</div>

Put above script at the bottom of html document or fire this snippet on DOMContentLoaded event like this:
<script type="text/javascript">
    document.addEventListener("DOMContentLoaded", function(event) { 
        var el = document.querySelector('.fc_img_tooltip_desc');
        el.textContent = el.textContent.replace(/\Bcm/, function(match){
            return ' ' + match; 
        })
    });
</script>

Update
If you have multiple elements to select, you have to use querySelectorAll() function:
<script type="text/javascript">
    document.addEventListener("DOMContentLoaded", function(event) { 
        document.querySelectorAll('.fc_img_tooltip_desc').forEach(function(value) {
            value.innerHTML = value.textContent.replace(/\Bcm/gi, function(match) {
                return ' <span class="highlight">' + match + '</span>';  
            })
        });
    });
</script>

