HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
With jQuery you select (query) HTML elements and perform "actions" on them
The jQuery syntax is tailor-made for selecting HTML elements and performing some action on the element(s).
Basic syntax is: $(selector).action()
Examples:
$(this).hide()
- hides the current element.
$("p").hide()
- hides all <p> elements.
$(".test").hide()
- hides all elements with class="test".
$("#test").hide()
- hides the element with id="test".
Are you familiar with CSS selectors?
jQuery uses CSS syntax to select elements. You will learn more about the selector syntax in the next chapter of this tutorial.
Tip: If you don't know CSS, you can read our CSS Tutorial.
You might have noticed that all jQuery methods in our examples, are inside a document ready event:
This is to prevent any jQuery code from running before the document is finished loading (is ready).
It is good practice to wait for the document to be fully loaded and ready before working with it. This also allows you to have your JavaScript code before the body of your document, in the head section.
Here are some examples of actions that can fail if methods are run before the document is fully loaded:
Use the syntax you prefer. We think that the document ready event is easier to understand when reading the code.