jQuery HTML Element How to - Highlight the first letter of each paragraph








Question

We would like to know how to highlight the first letter of each paragraph.

Answer


<!--  w  w w  .  ja  va  2 s.c  o  m-->
<html>
  <head>
    <script type="text/javascript" src='http://code.jquery.com/jquery-1.5.2.js'></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("div").slice(0, 1).wrapInner("<b></b>");
        });
    </script>
  </head>
  <body>
          <div>asdf</div>
          <div>asdf</div>
          <div>asdf</div>
          <div>asdf</div>
          
  </body>
</html>

The code above is rendered as follows: