This is a learning series for jQuery, In this series each article will have information related to jQuery that I feel every developer should know. Now a days, I have seen that many developers want to learn jQuery but they don’t know how to start. I would say if you are one of them or you want to know basics of jQuery then this learning series will be most helpful for you.
Following are the list of tutorials, which I will be posting on this blog:
In this article I will explain what is jQuery, why we use jQuery and why jQuery works well. If you already know all these things, you can skip this article and directly move into the second one.
What is jQuery and why we use jQuery?
What jQuery Does:
Modify the appearnce of a page: jQuery can change the classes or individual style properties applied to a portion of the document even after the page has been rendered. Alter the content of a Page: jQuery can modify the content of a document itself, like text can be changed, images can be inserted or swapped, list can be reordered etc. The most important things is jQuery library removes the browser specific complextity.
Why jQuery Works Well:
Always work with sets: When we instruct jQuery, For example, find all the elements with the class “collapsible” and hide them, there is no need to loop through each returned element. Instead methods such as .hide() are designed to automatically works on set of objects instead of individula ones.
Allow multiple actions in one line: To avoid overuse of temporary variables or wastful repetition, jQuery follow a programming pattern called chaining for the majority of its methods. This means that the result of the most operations on an object is the object itself, ready for the next action to be applied to it.
So now you know why jQuery is so important, let me give you one glimpse of jQuery with this example.
For example: If I write: $(‘p’).addClass(’emphasized’);
This will find all parts of the document that have the p tag attached with them and will add ‘emphasized’ class to selected elements.
How does it work:
The fundamental operation in jQuery is selecting a part of the document. This is done with the $() construct. The $() function is actually a factory for the jQuery Object. Typically it takes a string as a parameter, which can contain any css selector expression, like “id name”, “class name” etc.
Injecting the New Class:
addClass method adds a css class to the part of the page that we have selected and removeClass method removes a class.
That’s it for now. Thanks for reading this article. In my next article I will write, how to get anything from HTML page by using jQuery and how to modify them.