Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use jQuery :first Selector?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 149
    Comment on it

    Hi Reader's,
     Welcome to FindNerd, today we are going to discuss how to use jQuery :first Selector?

     Basically :first selector is used for selecting the first element and it is always use in a group.
     The :first selector  can only select one single element.

    syntax of :first Selector

    $(":first")

    You can see below example for better understanding:

    <!DOCTYPE html>
    <html>
      <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
       <!-- start css part -->
       <style>
          #paragraph {
                  max-width: 600px;
                  margin: 0 auto;
                  color:black;
               }
       </style>
       <!-- end css part -->
       
        <script>
        $(document).ready(function(){
          //call here :first Selector and also put css for effect
            $("p:first").css("background-color", "green");
        });
        </script>
    
      </head>
        <body>
    
       <div id = "paragraph">
          <p>First paragraph.</p>
          <p>Second paragraph.</p>
          <p>Last paragraph.</p>
       </div>
        </body>
    </html>
    

    In above code you can see First Parameter will be selected with green color.

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: