Document directory
Jquery syntax
The jquery syntax is compiled for the selection of HTML elements. You can perform some operations on the elements.
The basic syntax is:$ (Selector). Action ()
-
- Dollar sign defines jquery
- Selector: "query" and "Search" HTML elements
- Jquery action () executes operations on Elements
Example
$ (This). Hide ()-hide the current element
$ ("P"). Hide ()-hide all paragraphs
$ ("P. test"). Hide ()-hide all paragraphs of class = "test"
$ ("# Test"). Hide ()-hide all Id = "test" Elements
Tip: jquery uses a combination of xpath and CSS selector syntax. In the subsequent sections of this tutorial, you will learn more about the selector syntax.
Jquery syntax example
-
$ (This). Hide ()
-
Demonstrate the jquery hide () function to hide the current HTML element.
-
$ ("# Test"). Hide ()
-
Demonstrate the jquery hide () function to hide the element id = "test.
-
$ ("P"). Hide ()
-
Demonstrate the jquery hide () function to hide all <p> elements.
-
$ (". Test"). Hide ()
-
Demonstrate the jquery hide () function to hide all the elements of class = "test.
-
Jquery element Selector
Jquery uses the CSS selector to select HTML elements.
$ ("P") Select the <p> element.
$ ("P. Intro") select all <p> elements of class = "Intro.
$ ("P # Demo") Select the first <p> element of ID = "Demo.
Jquery attribute Selector
Jquery uses an XPATH expression to select an element with a given attribute.
$ ("[Href]") selects all elements with the href attribute.
$ ("[Href = '#']") select all elements with an href value equal.
$ ("[Href! = '#'] ") Select all elements with an href value not equal.
$ ("Your href00000000'.jpg ']") select all elements whose href values end with ". jpg.
Jquery CSS Selector
The jquery CSS selector can be used to change the CSS attributes of HTML elements.
The following example changes the background color of all P elements to Red:
Instance
$("p").css("background-color","red");