Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • What are selectors in jQuery and how many types of selectors are there ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.45k
    Comment on it

    Hello Readers,

    Jquery selectors is basically a key using with jquery library. Jquery selectors are one of the most important aspects of the jquery library. These jquery selectors are familiar with CSS and use with CSS syntax to allow page easily identify any set of page elements to operate upon with jquery library method.

    Syntax of jquery selector:

    $(selector).methodName();
    

    In the above, selector syntax (string expression) that identifies the set of DOM elements that will be collected into a matched set (operated upon by jquery library methods).

    JQuery operations can also be chained:

    Chained syntax:

    $(selector).method1().method2().method3();
    

    Alternately,

    1. To find the html element in jQuery we use selectors.
    2. To work with an element on the web page, first we need to find them.

    There are many types of selectors but basic selectors are:

    1. Name : Selects all elements which match with the given element Name. The element name selector enables you to select elements by their names certain type or kind. For instance, all anchor elements, or paragragh elements.

    Syntax:

    $('a');
    

    For Example:

    $('a').css('background-color', '#00ff00');
    

    1. #ID :
    Selects a single element which matches with the given ID

    For Example:

    <script type="text/javascript">
    $(document).ready(function() {
        $('#theId').css('background-color', '#00ff00');
    });
    </script>
    
    <div id="theId">
        text
    </div>btn btn-primary
    

    1. .Class :
    Selects all elements which match with the given Class.

    For Example:

    $('.theClass').text();
    

    1. Universal(*) :
    Selects all elements available in a DOM.

    The jquery universal selector syntax :

    $("*")
    

    For Example:

    <script>
    $(document).ready(function(){
    $("body>*").css("background-color","orange");
    });    
    </script>
    

    1. Multiple Elements E,F,G :
    Selects the combined results of all the specified selectors E, F or G.

    1. Attribute Selector :
    Select elements based on its attribute value.

    Syntax:

    $('[height]');
    

 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: