Selectors in jquery



In this post I will tell you aboy selectors in Jquery and how they are different from JavaScript

JQuery provides us many ways of selecting elements from the page which are short and simple as compared to JavaScript as we know the purpose to use jQuery us to write less code and get more functionalities.

There are many different type of selectors in jQuery

1.Basic Selectors:-

These selectors are very simple and commonly use in jquery selectors they include
ID SELECTORS
ID SELECTORS allows us to select the page element on the basis of id or we may say that we can select the page element with there id.This selector is the replacement for getElementsById()
for eg suppose we have a HTML element as

This is a paragraph

By using jquery id selector we can select element as
var Para = $(‘#idname’);
Note:Don’t forget to use # in id selector

ELEMENT SELECTORS
Jquery has the replacement for getElementsByTagName() which is known to be element selector Lets take a example to understand in better way
var linksList = document.getElementsByTagName(‘a’); In jQuery we can write this as
var linksList = $(‘a’);

CLASS SELECTORS
CLASS SELECTORS allows us to select pager element on the basis of class lets take example to understand in better way
suppose we want to hide the elements of banner class with the use of jQuery we can do like
$(‘.banner’).hide();
the above command will hide the banner class element.