Valid XHTML 1.0 Transitional

jQuery: Select the first of a set of elements with p:first

This is paragraph 1.

This is paragraph 2.

This is paragraph 3.

This is paragraph 4.

The Code START
  <script type="text/javascript" src=""></script>
    <script type="text/javascript">
      function setStyle1() {
         $('p:first').css("font-style", "italic");
      function setStyle2() {
         $('p:last').css("font-weight", "bold");
      function resetStyle() {
        $('p:first').css("font-style", "normal");
        $('p:last').css("font-weight", "normal");
    <style type="text/CSS">
        .code { color: red; }
        .back { background-color: yellow; }

  <h1>Select the first of a set of elements with p:first</h1>
  <p>This is paragraph 1.</p>
  <p>This is paragraph 2.</p>
  <p>This is paragraph 3.</p>
  <p>This is paragraph 4.</p>
  <form action="">
   <input type = "button" value="Style first paragraph" onclick="setStyle1()"></input>
   <input type = "button" value="Style last paragraph" onclick="setStyle2()"></input>
   <input type = "button" value="Undo Styles" onclick="resetStyle()"></input>