1. jquery Selector
Used to select an element object on a page. The way the jquery selector completely inherits the CSS Selector
jquery Selector is the basis for learning jquery
How to get the element objects in a page in the DOM. --Three different ways
How to get the elements on a page directly from the jquery way. (Directly after acquisition is a jquery object)
ID selector $ (' #id ')
Tag Selector $ (' span ')
Class Selector $ ('. CLS ')
Tag Plus class selector $ (' div.cls ')
Multi-condition Selector $ (' H1,p,span ')
All span elements in the layer selector $ (' div span ')--div
$ (' Div>span ') all the direct span elements in the--DIV
$ (' Div+span ')--div the first element span after
$ (' Div~span ') all span labels after--div
2. Several ways to get sibling elements
Next () The first sibling element immediately after the current element
Nextall () All sibling elements after the current element
Prev () The previous sibling element before the current element
Prevall () All sibling elements before the current element
Siblings () except itself, all the other sibling elements
3. jquery iteration (packing set)
How to tell if an object exists, the jquery selector returns an array of objects,
The method called the text () HTML () Click () is actually an iterative invocation of each method for each element of the array.
Therefore, even if the element selected by ID does not exist, there is no error.
If you need to determine whether the specified ID exists, you should write
if ($ (' #btn '). length<=0) {
An element with alert (' ID ' btn1 does not exist. ');
}
$ (' #id '). Length>0 Purpose: You can determine whether an element on a page exists, and if it does not
Recreate, if not present, create a new and display (with dynamic creation of elements)
4. Chain programming must pay attention to when the chain of destruction
such as the current object's delivery, such as using Nextall (), the current object's delivery is corrupted,
You can call the end () method to return the object before the chain is corrupted
5. AddClass (' class ') Add Style removeclass (' class ') Remove style
Toggleclass (' class ') Toggle Style hasclass (' class ') to determine whether a style has been applied
6. Basic Filter Selector
Get first element
$ (' P:first '). CSS (' backgroundcolor ', ' green ');
$ (' P '). (a). css (' backgroundcolor ', ' green ');
Get the last element
$ (' P:last '). CSS (' backgroundcolor ', ' green ');
$ (' P '). Last (). CSS (' backgroundcolor ', ' green ')
Even
$ (' P:even '). CSS (' backgroundcolor ', ' green ');
Odd
$ (' p:odd '). CSS (' backgroundcolor ', ' green ');
Index FETCH Element
$ (' P:eq (3) ')--p with index equal to 3
$ (' P:lt (3) ')--all p with index less than 3
$ (' P:gt (3) ')--all p with index greater than 3
$ (' P:gt (2): LT (2) ')--index is greater than 2 and less than 2 (i.e. original 3,4)
Not
$ (' P:not (. Class) ')
Set Header
$ (' H1,h2,h3,h4,h5,h6 '). CSS (' backgroundcolor ', ' green ');
A simple formulation
$ (': Header '). css (' backgroundcolor ', ' green ');
7. Relative positioning
Not only can you use selectors for absolute positioning, but also relative positioning
As long as the second argument is specified in $ (), the second argument is the relative element
$ (Selector,context)
Take a couple of columns per row in a table
$ (' Td:even ', $ (this)). CSS (' backgroundcolor ', ' red ');
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service