jQuery is a JavaScript library that makes it easier to interact with elements on your page. It uses this syntax:
$(selector).action()
You can select HTML elements by #class, .id, or with a tag like
. Non-existing elements can also be selected with the $ function, and they will be created.
By selecting an HTML element, we create an array-like object that stores many useful methods. We can add elements before and after with append and prepend, add a class, animate, and much more. It is important to not that it is an array-like object for iteration over selected elements.
One important method to note is .css. We can grab an html element, and edit any css property on the fly in our JavaScript code. It would look something like this:
$('p').css('color', 'black')
Note that many jQuery methods will return the object with all the methods in it, so chaining them together is possible.
Lastly, jQuery is great for handling events! Using the .on method, we can define an event like 'click' or 'hover', and write a function to be executed upon such an event. This allows to create dynamic elements on our page that the user can interact with.
It's important to know jQuery because of it's broad usage over the course of the internet's history, but it is also important to note another library called react. React may be imperative to use if your project involves a large number of elements, as it is more efficient with these types of projects. I would encourage looking it up and comparing the pros and cons of both!
Top comments (0)