jQuery Syntax

With jQuery you select (question) HTML components and perform "actions" on them.

jQuery Syntax

The jQuery sentence structure is customized for selecting HTML components and playing out some action on the element(s).

Basic sentence structure is: $(selector).action()

  • A $ sign to characterize/get to jQuery
  • A (selector) to "query (or find)" HTML elements
  • A jQuery action() to be performed on the element(s)


$(this).hide() - conceals the current element.

$("p").hide() - conceals all <p> elements.

$(".test").hide() - conceals all components with class="test".

$("#test").hide() - conceals the component with id="test".

The Report Prepared Event

You may have seen that all jQuery techniques in our models, are inside a report prepared event:


   //jQuery strategies go here...


This is to keep any jQuery code from running before the record is done stacking (is ready).

It is great practice to trust that the report will be completely stacked and prepared before working with it. This additionally enables you to have your JavaScript code before the body of your record, in the head segment.

Here are a few instances of activities that can come up short if techniques are kept running before the record is completely loaded:

  • Trying to conceal a component that isn't made yet
  • Trying to get the span of a picture that isn't stacked yet

Tip: The jQuery group has additionally made a considerably shorter strategy for the record prepared event:


   //jQuery strategies go here...


Use the linguistic structure you lean toward. We feel that the archive prepared occasion is less demanding to comprehend when perusing the code.