Get last paragraph and add class : Selector tag class « jQuery « JavaScript DHTML






Get last paragraph and add class

      
<html>
  <head>
    <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
              $("p:last").addClass("selected");

        });
    </script>
    <style>
       .selected { color:red; }
    </style>
  </head>
  <body>
    <body>
      <p>A</p>
      <p>B</p>
      <p>C</p>
  </body>
</html>

   
    
    
    
    
    
  








Related examples in the same category

1.Finds every DIV element.
2.Finds the element with the class "myClass".
3.Finds the elements that match any of these three selectors.
4.Select tag by name
5.Select tag and its class
6.Select from nested classes
7.Select based one just added
8.Matches all elements with the given class
9.Query just added tags
10.Find the very next sibling of each paragraph that has a class "selected".