With JQuery, you can select (query) HTML elements and perform actions on them.
jQuery Syntax Instance $ ( This). Hide () demonstrates the jQuery hide () function, which hides the current HTML element. $("#test"). Hide () demonstrates the jQuery hide () function, hiding the ID="Test"the element. $("P"). Hide () demonstrates the jQuery hide () function, hiding all<p>element. $(". Test"). Hide () demonstrates the jQuery hide () function, hiding allclass="Test"The element.
JQuery syntax
The jQuery syntax is for the selection of HTML elements, and you can perform certain operations on elements.
The underlying syntax is: $ (selector). Action ()
- Dollar sign definition JQuery
- Selector (selector) "Query" and "find" HTML elements
- JQuery Action () performs an operation on an element
Example
$ (this). Hide ()-hides the current element
$ ("P"). Hide ()-Hides all paragraphs
$ (". Test"). Hide ()-hides all elements of class= "test"
$ ("#test"). Hide ()-hides all elements of the id= "test"
Tip: The syntax used by JQuery is a combination of XPath and CSS selector syntax. In the next chapters of this tutorial, you will learn more about selectors syntax.
Document-Ready functions you may have noticed that all of the jQuery functions in our instance are in one of the document readiness functions: $ (document). Ready (function () {---jQuery functions Go here----}); This is to prevent the document from running JQuery code before it is fully loaded (ready). If you run the function before the document is fully loaded, the operation may fail. Here are two specific examples: trying to hide a nonexistent element to get the size of an image that is not fully loaded
Sample code
<! DOCTYPE html>"/jquery/jquery-1.11.1.min.js" ></script><script>$ (document). Ready (function () { $ ("P" ). Click (function () { $ (this). Hide (); });}); </script>
"Text/javascript"Src="Jquery.js"></script><script type="Text/javascript">$ (document). Ready (function () {$ ("Button"). Click (function () {$ ("P"). Hide ();} );</script> isA heading isA paragraph.</p><p>this isAnother Paragraph.</p><button type="Button">click me</button></body>JQuery Syntax (i)