Author: one page kite
Writing time: on April 30, 2020,
1. Introduction of jQuery
1. What is a jQuery?
JQuery is a JavaScript function library,
JQuery is a lightweight "write less, do more" JavaScript libraries,
The jQuery library contains the following functions:
The HTML element to select
The HTML element operation
CSS operation
HTML event functions
JavaScript effects and animation
The HTML DOM traversal and modify
AJAX
Utilities,
Tip: in addition to this, the jQuery also provides lots of plugins
2. How to use jQuery
JQuery is a JavaScript library, do not need special to install, only need us among the page tag, through & lt; script> Label is introduced into the jQuery library can
JQuery download address: https://jquery.com/download/
3. The grammar of the jQuery
JQuery syntax is through select HTML element, and the selection of elements to perform certain operations
Basic syntax: $(selector). The action ();
- $$symbol definition jQuery
- the selector selectors should find elements to support css1 ~ the mainstream selector in CSS 3
- the action () to the operation of the element
For example:
$(" p "). Hide ();//hide all & lt; P> The element
2. The jQuery object with the DOM object in the JS
1. The jQuery selector
Any operation needs the support of the node of the page, how fast and efficient developers find specified node was one of the front-end development focus,
JQuery provides a series of selector to help developers to achieve this goal, let developers can choose less complex process and performance optimization, more focus on business logic written,
JQuery support mainstream css1 almost ~ the range selector method and we start from the simplest and most commonly used in English:
2. The ID selector $(" # ID ");
Id selector is also the basic selector, jQuery internal use JavaScript function document. The getElementById () to handle id,
Native syntax support is always very efficient, so on the operation of the DOM, if can use id always consider using the selector
Statement:
Var box=document. GetElementById (" box ");//js the statement in
Var box=$(" # box ");//in the jQuery statement
Can be seen from the above two sentences, more easily in the jQuery
Note: the id is unique, each id value can be used only once in a page, if multiple elements are assigned the same id,
Will match the id only choice set first DOM elements, but this should not happen; Have more than one element of the page using the same id is invalid
3. The class selector $(" classname ");
Class selectors, id selectors relatively, the efficiency is relatively low, but the advantage is that you can choose more
The same jQuery on the implementation, for class selectors, if the browser support, use the jQuery JavaScript native getElementsByClassName () function to achieve
Var box=document. GetElementsByClassName (" box ");//js the statement in
Var box=$(" box ");//in the jQuery statement
Can be seen from the above two sentences, more easily in the jQuery
4. Element element selectors $(" label name ");
Element selectors, choose all of the elements according to a given HTML tag name
Specify the element tag name search all the nodes, this is a collection operation, as well as with native method getElementsByTagName () function support
Var box=document. GetElementsByTagName (" div ");//js the statement in
Var divs=$(" div ");//in the jQuery statement
5. The selector $(" * ")
The selector, i.e., * selector
In CSS, often in the first row to write such a style
* {padding: 0; margin: 0; }
Wildcard * means to set default margins, all of the elements in the jQuery we can by passing * selector to select the elements in the document page
Statements;
//output all page elements
Var allElement=$(" * ");
The console. The log (allElement);
6. Level selector
Between all nodes in the document are relationship of one sort or another, we can put the relationship between the nodes can be used to describe the traditional family relations,
As a document tree tree, nodes and between nodes may exist father and son, brothers, the relationship between the two generations,
Selector in the hierarchy selector is used to deal with the relationship between
Child elements offspring element sibling elements adjacent element
Through a list, the difference between contrast level selector
Selector description
$(" ancestor descendant ") descendant selectors: choose a given ancestor element of all descendant elements, the offspring of an element may be a child of the element, the son, the son of
$(" parent & gt; The child ") child selectors: direct child elements of the parent
$(" prev + next ") adjacent brother selector: match all immediately after prev elements of the next element
$(" prev ~ siblings ") general brothers selector: after prev elements all the siblings of the matched elements
3. The jQuery selector other basic screening selector attribute selectors, etc.
Many times we can't directly through basic selector and element level selector to find what we want,
For jQuery provides a series of screening option is used to more quickly find the DOM element,
Screening selector is not a lot of CSS specification, but the jQuery selector for the convenience of developers extend out
Pseudo elements in the screening and CSS selector usage similar, choose for colon ":" the beginning, the description of the basic filter to see jQuery
The API documentation:
The selector
$(" : the first ") for the first matched elements such as: $(' li: first);
$(" : the last ") for the end of the match elements such as: $(' li: the last);
$(" : not selector () ") to remove all with a given selector of the matched elements such as: $(" input: not (checked) ")
$(", even ") to match all index value is an even number of elements, starting from 0, for example: $(" li: even ")
: $(" odd ") to match all index value is an odd number of elements, starting from 0, for example: $(" li: odd ")
$(" : eq (index) ") to match a given index value elements, starting from 0, for example: $(" li: eq (1) ")
$(" : gt (index) ") all index greater than a given value of the matched elements, starting from 0, for example: $(" li: gt (0))
$(" : lt (index) ") to match all elements of index of less than a given value, starting from 0, for example: $(" li: gt (2) ")
: $(" header ") match such as h1, h2, h3, such as the title of the elements such as: $(" : the header "). The CSS (" background ", "# EEE");
$(" : the animated ") match all executing animated elements (only to not perform the animation effects elements perform an animation effects)
For example: $(" : the header "). The CSS (" background ", "# EEE");
: $(" focus ") to match the current focus element,
$(" root ") select the document root element, in HTML, the root element of the document, and $(" root ") selected element, is always & lt; Html> Element,
Example: set & lt; Html> Background color for yellow
$(" root "). The CSS (" background - color ", "yellow");
Remember:
1. The attribute selectors
2 the content of the jQuery selector screen selector
3 the jQuery selector visibility of screening selector
Four properties of jQuery selector screen selector
The child of 5 jQuery selector elements selection selector
6 the jQuery selector form elements of the selector
Seven of the jQuery selector screening form object attribute selectors
JQuery API manual
CodePudding user response:
Query based on the use and style articleCodePudding user response:
Query based on the use and style articleCodePudding user response:
Query based on the use and style article