JQuery Selector class

From CoderLearner
Jump to: navigation, search

Description

It is a class selector.

Syntax

$(".classname");

Example 1

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Select</title>
      <script 
         type="text/javascript" 
         src="/lib/jquery-1.7.2.min.js">				 
      </script>
      <style>
         .mark1 {
           color:red;
         }
         .mark2 {
            background-color:#f9f9f0;
            width:230px;
         }

      </style>
      <script>
         $().ready(function() {
            $('.mark').addClass('mark1');
            $('.inputmark').addClass('mark2');
         });
      </script>
   </head>
   <body> 
      <ul>
         <li class="mark">One</li>
         <li class="mark">Two</li>
         <li class="mark">Three</li>
      </ul>
      <input type="text" name="fname" class="inputmark"/>
      <input type="text" name="lname" class="inputmark"/>
   </body>
</html>

Try It