# JQuery Selector

In 
web
Published 2022-12-03

This tutorial explains to you the concept of JQuery selector. I will answer to the following questions: What a JQuery Selector is ? Which are the JQuery selectors ?

# What a JQuery Selector is ?

Selectors are used to select one or more HTML elements using jQuery.Once an element is selected then we can perform various operations on that selected element. JQuery selectors allow you to select and manipulate HTML element(s).

jQuery selectors are used to select HTML elements based on their name, id, classes, types, attributes, values of attributes and much more. It's based on the existing CSS Selectors, and in addition, it has some own custom selectors.

All selectors in JQuery start with the dollar sign and parentheses: $().

# JQuery selectors Examples

  • For selecting all "div1" elements:
$("div1")
  • When click on buttons, we do an action ("hide" for instance) on all "div1" elements:
$(document).ready(function(){
  $("button").click(function(){
     $("div1").hide();
  });
});
  • When click on buttons, we do an action ("hide" for instance) on the "div1" element:
$(document).ready(function(){
  $("button").click(function(){
    $("#div1").hide();
  });
});
  • When click on buttons, we do an action ("hide" for instance) on the class "class1" elements:
$(document).ready(function(){
  $("button").click(function(){
    $(".class1").hide();
  });
});

More information you can get from W3schools.