May 06, 2021 JavaScript
Test javaScript framework library - jQuery
To test the JavaScript library, you need to reference it in a Web page.
In order to reference a library, use the hashtag, whose src property is set to the URL of the library:
The main jQuery function is the $() function (jQuery function). If you pass a DOM object to the function, it returns the jQuery object with the jQuery feature added to it.
jQuery allows you to select elements through the CSS selector.
In JavaScript, you can assign a function to handle window load events:
The equivalent jQuery is different:
On the last line of the code above, the HTML DOM document object is passed to jQuery:$.
When you pass a DOM object to jQuery, jQuery returns the jQuery object wrapped in html DOM objects.
The jQuery function returns a new jQuery object, where ready() is a method.
Because functions are variables in JavaScript, you can pass myFunction as a variable to jQuery's ready method.
jQuery returns the jQuery object, unlike the doM object that has been passed.
The jQuery object has different properties and methods than the DOM object. You cannot use html DOM properties and methods on jQuery objects. |
Try this example:
Try this example again:
As you can see in the example above, jQuery allows links (chain syntax).
Chaining is a convenient way to perform multiple tasks on the same object.
Need to learn more? W3Cschool gives you a great jQuery tutorial.