It is used to select elements in the HTML and perform actions on those elements.
The syntax is as follows:
$(selector).action()
$ symbol: It grants access to jQuery.
(Selector): This is used to find HTML elements.
jQuery action(): Used to perform operations on the element.
- Used to hide the current element.$(this).hide()
- Used to hide all < p> elements.$(“p”).hide()
- Used to hide all elements with class=”test”.$(“.test”).hide()
- Used to hide id=”test” element.$(“#test”).hide()
File Ready Events:
The jQuery method is located in the Document ready event and makes it easy to read the code. $(document).ready(function(){// jQuery method}); This is to check and stop jquery before finishing loading the document. This method also allows you to include JavaScript code at the beginning of the body of the document.
If the method is run before the loaded document, some operations may fail:
Gets image dimensions that haven’t been loaded yet, or hides image elements that haven’t been created yet.
Shorter ways to prepare documents: $(function(){// jQuery Method});