Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • jQuery - Selectors

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 362
    Comment on it

    A function which allows us to select and manipulate HTML element(s) and  makes use of expressions to find organizing components from a DOM is known as Jquery Selectors.

    We can find HTML elements by their name, id, classes, types, attributes, values of attributes etc.

    The factory function is the functions from which the jQuery selector starts and they are dollar sign and parentheses $() as listed below :- 

    1. Tag Name: Signifies a tag name available in the DOM.

    For example $('p') selects all paragraphs <p> in the document.

     

    2. Tag ID: Signifies a tag available with the given ID in the DOM.

    For example $('#any-id') selects the single element in the document that has an ID of any-id.

     

    3. Tag Class: Signifies a tag available with the given class in the DOM.

    For example $('.any-class') selects all elements in the document that have a class of any-class.

     

    Following is a simple example which makes use of Tag Selector.

    <html>
       <head>
          <title>The jQuery Example</title>
          <script type = "text/javascript" 
             src = "http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
          <script type = "text/javascript" language = "javascript">
             $(document).ready(function() {
                $("p").css("background-color", "red");
             });
          </script>
       </head>
        
       <body>
          <div>
             <p class = "myclass">This is a first example.</p>
             <p id = "myid">This is second example.</p>
             <p>This is third example.</p>
          </div>
       </body>
        
    </html>

     

 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: