jQuery Basic Syntax


jQuery syntax is simple and easy to understand.

Every jQuery statement follows a basic pattern where elements are selected and actions are performed on them.

The general jQuery syntax looks like this:

$(selector).action();

This structure is used in all jQuery programs.

In this example, the selector selects all paragraph elements and the action hides them.

This simple syntax makes jQuery very powerful and easy to learn.

Here, the selector selects an element with id 'btn' and performs an action when it is clicked.

Selectors define which HTML element jQuery should work with.

This code selects all elements with class 'box' and changes their text color.

jQuery syntax closely follows CSS selector patterns.

Important Syntax Rules:

  • jQuery code starts with $
  • Selectors choose HTML elements
  • Actions perform tasks
  • Statements end with semicolon
  • Syntax is similar to CSS selectors