jQuery Page Widget How to - Find certain text on page and make it bold








Question

We would like to know how to find certain text on page and make it bold.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!--from  ww  w.java2 s.c o  m-->
    $('p').html( $('p').html().replace(/hello/g, '<strong>hello</strong>') )
});
</script>
</head>
<body>
  <p>this is a test hello.</p>
</body>
</html>

The code above is rendered as follows: