05 Nov jQuery Syntax
In the previous lesson, we learned how to run jQuery on local machine to begin working in Windows. Here, we will see how to start with jQuery by learning about its syntax. While working with jQuery, you can use all the functions of JavaScript. Let’s learn about jQuery syntax.
Here’s the syntax,
jQuery uses a document ready event, which we will learn in the upcoming lessons also,
1 2 3 4 5 |
$(document).ready(function() { // code }); |
The above function prevents the code from running before the document is ready.
Now, you can also use the $() to write the above code. The meaning and purpose of the code remain the same,
1 2 3 4 5 |
$(function() { // code }); |
The syntax used inside the document ready event,
1 2 3 |
$(selector).action() |
Here,
- $ = Sign denotes jQuery function to define jQuery
- selector = To select HTML elements
- actions = To perform an action on select element
We will be using the following syntax,
1 2 3 4 5 6 |
$(document).ready(function() { // code }); |
Let’s see an example to run jQuery on the local system:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ document.write("First Script! Studyopedia.com"); }); </script> </head> <body> <h1>Studyopedia</h1> </body> </html> |
Output
No Comments