.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Interview Question >> JQuery >> Post New Question Subscribe to Interview Questions

What are selectors in jQuery and how many types of selectors are there?

Posted By :abhays     Posted Date :August 15, 2014    Points :40   Category :JQuery 
To work with an element on the web page, first we need to find them.

To find the html element in jQuery we use selectors. There are many types of selectors but basic selectors are:

Name: Selects all elements which match with the given element Name.

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

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

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

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

Attribute Selector: Select elements based on its attribute value.

that have an odd index value.

$("li:first"): Selects the first
  • element.

    $("li:last"): Selects the last
  • element.

    $("li:visible"): Selects all elements matched by
  • that are visible.

    $("li:hidden"): Selects all elements matched by
  • that are hidden.

    $(":radio"): Selects all radio buttons in the form.

    $(":checked"): Selects all checked boxex in the form.

    $(":input"): Selects only form elements (input, select, textarea, button).

    $(":text"): Selects only text elements (input[type=text]).

    $("li:eq(2)"): Selects the third
  • element

    $("li:eq(4)"): Selects the fifth
  • element

    $("li:lt(2)"): Selects all elements matched by
  • element before the third one; in other words, the first two
  • elements.

    $("p:lt(3)"): selects all elements matched by

    elements before the fourth one; in other words the first three


    $("li:gt(1)"): Selects all elements matched by

  • after the second one.

    $("p:gt(2)"): Selects all elements matched by

    after the third one.

    $("div/p"): Selects all elements matched by

    that are children of an element matched by


    $("div//code"): Selects all elements matched by that are descendants of an element matched by
  • that are the first child of their parent.

    $("li:last-child"): Selects all elements matched by
  • that are the last child of their parent.

    $(":parent"): Selects all elements that are the parent of another element, including text.

    $("li:contains(second)"): Selects all elements matched by
  • that contain the text second.

    You can use all the above selectors with any HTML/XML element in generic way. For example if selector $("li:first") works for
  • element then $("p:first") would also work for

    element. (More...)

    All types in C# implicitly derive from.........

    System.Object Class. System.Object is the parent class of all .NET classes (More...)

    What are the types of indexes available with SQL Server?

    There are basically two types of indexes that we use with the SQL Server. Clustered and the Non-Clustered. (More...)

    Different Types of Remote Objects?

    The remoting infrastructure allows you to create two distinct types of remote objects.

    1.Client-activated objects - A client-activated object is a server-side object whose creation and destruction is controlled by the client application. An instance of the remote object is created when the client calls the new operator on the server object. This instance lives as long as the client needs it, and lives across one to many method calls. The object will be subject to garbage collection once it''s determined that no other clients need it.

    2.Server-activated objects - A server-activated object''s lifetime is managed by the remote server, not the client that instantiates the object. This differs from the client-activated object, where the client governs when the object will be marked for finalization. It is important to understand that the server-activated objects are not created when a client calls New or Activator.GetObject. They are rather created when the client actually invokes a method on the proxy. There are two types of server activated objects. They are:

    I. Single call . Single-call objects handle one, and only one, request coming from a client. When the client calls a method on a single call object, the object constructs itself, performs whatever action the method calls for, and the object is then subject to garbage collection. No state is held between calls, and each call (no matter what client it came from) is called on a new object instance.

    II.Singleton - The difference in a singleton and single call lies in lifetime management. While single-call objects are stateless in nature, singletons are stateful objects, meaning that they can be used to retain state across multiple method calls. A singleton object instance serves multiple clients, allowing those clients to share data among themselves. (More...)

    what are value types and reference types?

    Value type - bool, byte, chat, decimal, double, enum , float, int, long, sbyte, short, strut, uint, ulong, ushort
    Value types are stored in the Stack
    Reference type - class, delegate, interface, object, string
    Reference types are stored in the Heap (More...)

    What are the types of threading models?

    . Single Threading: This is the simplest and most common threading
    model where a single thread corresponds to your entire application's
    Apartment Threading (STA): This allows multiple threads to exist in a
    single application. In single threading apartment (STA), each thread
    is isolated in it's own apartment. The process may contain multiple
    threads (apartments) however when an object is created in a
    thread (i.e. apartment) it stays within that
    apartment. If any communication needs to occur between different
    threads (i.e. different apartments) then we must marshal the first
    thread object to the second thread.
    Free Threading: The most complex threading model. Unlike STA,
    threads are not confined to their own apartments. Multiple treads can
    make calls to the same methods and same components at the
    same time. (More...)

    How many types of tables are present in SQL SERVER?

    There are 2 types of temporary tables, local and global in sql server.

    Local temporary tables are created using a single pound (#) sign and are visible to a single connection and automatically dropped when that connection ends.

    Global temporary tables are created using a double pound (##) sign and are visible across multiple connections and users and are automatically dropped when all SQL sessions stop referencing the global temporary table. (More...)

    What are the different types of Assembly?

    There are two types of assembly Private and Public assembly.

    A private assembly is normally used by a single application, and is stored in the application's directory, or a sub-directory beneath. A shared assembly is normally stored in the global assembly cache, which is a repository of assemblies maintained by the .NET runtime. Shared assemblies are usually libraries of code which many applications will find useful, e.g. Crystal report classes which will be used by all application for Reports. (More...)

    What are different types of JIT?

    JIT compiler is a part of the runtime execution environment.
    In Microsoft .NET there are three types of JIT compilers:
    .Pre-JIT: - Pre-JIT compiles complete source code into native code in a single compilation cycle. This is done at the time of deployment of the application.
    .Econo-JIT: - Econo-JIT compiles only those methods that are called at runtime. However, these compiled methods are removed when they are not required.
    .Normal-JIT :- Normal-JIT compiles only those methods that are called at runtime. These methods are compiled the first time they are called, and then they are stored in cache. When the same methods are called again, the compiled code from cache is used for execution. (More...)

    What are Value types and Reference types?

    Value types directly contain their data which are either allocated on the stack or allocated in-line in a structure. Reference types store a reference to the value's memory address, and are allocated on the heap. Reference types can be self-describing types, pointer types, or interface types. Variables that are value types each have their own copy of the data, and therefore operations on one variable do not affect other variables. Variables that are reference types can refer to the same object; therefore, operations on one variable can affect the same object referred to by another variable. All types derive from the System.Object base type. (More...)

  • You can also find related Interview Question to What are selectors in jQuery and how many types of selectors are there?  below: 

    There are 3 types of selectors in Jquery?

    1. CSS Selector
    2. XPath Selector
    3. Custom Selector (More...)

    which are basic selectors in jQuery (cross browser)?

    ->Element ID's
    ->CSS class name
    ->Tag name
    ->last but not the least DOM hierarchy. (More...)

    What is jQuery Selectors

    jQuery Selectors are used to select one or a group of HTML elements from your web page.
    . jQuery support all the CSS selectors as well as many additional custom selectors.
    . jQuery selectors always start with dollar sign and parentheses: $()
    . There are three building blocks to select the elements in a web document.

    Select elements by tag name
    Select elements by ID
    Select elements by class (More...)

    Explain different type of useful selectors in jQuery.

    Below is the list of different types of useful selectors in jQuery

    $('*'): This selector selects all elements in the document.

    $("p > *"): This selector selects all elements that are children of a paragraph element.

    $("#specialID"): This selector function gets the element with id="specialID".

    $(".specialClass"): This selector gets all the elements that have the class of specialClass.

    $("li:not(.myclass)"): Selects all elements matched by
  • that do not have class="myclass".

    $("a#specialID.specialClass"): This selector matches links with an id of specialID and a class of specialClass.

    $("p a.specialClass"): This selector matches links with a class of specialClass declared within


    $("ul li:first"): This selector gets only the first

  • element of the
  • Quick Links For Interview Questions Categories:
    ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
    Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
    Biztalk Patten/Practices .IIS WCF WPF WWF
    Networking Aptitude Others   All      

    Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

    Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

    So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.

    Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend