Page Content
Now I have started learning JQuery so I wanted to have my own concise tutorial article for JQuery. I hope this will be helpful to other beginners too.
Note*: There are other tutorial on web which is quite good, basically JQuery’s own tutorial. If you are looking for more details you can also look for the API document of JQuery.
What is JQuery and What is not
JQuery is open source lightweight Javascript Library which is used to simplify interaction between HTML and JavaScript.
JQuery is not a language. JavaScript is Language. JQuery is built over JavaScript.
What JQuery can do
- DOM Manipulation
- CSS Manipulation
- AJAX
- Effects and Animation
How to use JQuery
You can start using JQuery by adding the JQuery library in HTML file.
<!doctype html> <html> <head> <meta charset="utf-8" /> <title>Demo</title> </head> <body> <a href="https://Javabeginnerstutotrial.com/">JBT</a> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> </body> </html>
Imp Point in above code
- Here we are using JQuery.min.js instead of JQuery.js. In Production you should use minified version of library. It will load fast as it doesn’t contain unnecessary comment and whitespaces.
- JQuery is getting loaded from Google CDN instead of self hosting. It will again make your site load faster. Also it will help you website take advantage of cache.
JQuery Syntax
Now we know how to use JQuery in web page. Next step would be using JQuery syntax. Common syntax for JQuery would be
$(<Where_to_do_Action>).<When_To_Do_Action>(<What_To_Do>);
Example of JQuery Syntax
I want to show an alert message when ever document is ready or loaded completely.
Where(Selectors) : On Document.
When (Action): Document is in ready state or loaded completely.
What(Function) : Show an alert message.
Syntax in JQuery for above requirement
$(document).ready(alert("Hi"));
Different options for Selector(Where)
All Element – *
Current HTML element – this
Class – .<Class_Name> (look for dot)
Id – #<Id_Name> (look for #)
HTML element
- a (hyperlink)
- table
- tr
- td
- p
- …….
Complete HTML Code
<!doctype html> <html> <head> <meta charset="utf-8" /> <title>Demo</title> </head> <body> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script> $(document).ready(alert("Hi")); </script> </body> </html>
this is really helpful, thanks.
Understandable in a good way.
Nice site to learn
Very Good Explanation..! My Clouds are clear with the basic steps. Thanks
Very Nice And clear explantion…….. 5stars
can u post more detail about jquery
Thanks
Nice explanation..
Hi there, nice tutorial.
Thanks!
Nice way to begin my jquery concept ,thanks for the very clear explanation