The jquery! of inexplicable

Source: Internet
Author: User
Tags tag name

1. What is JQ,

JQ is in JS has a lot of problems, is used to wipe the buttocks of the package, can be particularly convenient to use a variety of APIs, set up a combination of solving JS problem, and also comes with the animation effect module, it is more suitable for the use of JQ.

2, why use JQ.

The shortcomings of JS mainly in compatibility and dynamic effect is more complex, resulting in a lot of code redundancy, so the use of JQ to a certain extent can avoid the sub-situation.

<! DOCTYPE html>

There are generally two ways of representing:

1,$ (ducoment). Ready (function () {})

2,$ (function () {})

The most important sign of JQ is the $, which represents the use of JQ

The difference between JQ and JS in acquiring node elements:

Js:var box = Ddoument.getelementbyid ("box"), jq:$ (#box) sets the style of the CSS: js:box.style.width = "10px" jq:$ (' #box '). css ({   ' Width ': ' 10px ',}) Mutual conversion mode:    1,JS-JQ: $ (JS object name)    2,JQ-JS:JQ Object [index];$ (' div ') [1].style.backgroundcolor = "Red"; Can directly convert the reference JQ object. Get (index);

Example: Interlaced color change:

<! DOCTYPE html>

3. Selector for JQ:

1, Base selector:

1,id selector: $ (#id名)

2, class selector: $ ('. Class name ')

3, Tag Selector: $ (' tag name ')
4, wildcard selector: $ (' * ') Select all.

2, Level selector:

1, descendant selector: selector for all descendant elements

$ (Parent class name descendant name)

2, descendant selector: Values Select all Descendants, parent son Select

$ (Parent class name > descendant name)

    

3, Basic filter selector:

1, select elements by ordinal:

$ (' Li:eq (1) ') selected starting from 0

2, select all elements with an ordinal greater than index:

$ (' li:gt (1) ')

3, select all elements with an ordinal less than index:

$ (' li:it (1) ')

4, select all elements with an odd number of rows

$ (' li:odd ')

5, select all elements with an even number

$ (' Li:even ')

6,,7, select the first and last items:

$ (' Li:first ') $ (' Li:last ')

<! DOCTYPE html>

4, Property selector:

5, filter selector:

1, until the specified element:

$ (' #box '). Find (selector) finds all descendant elements of the specified element, all descendants!

2, finds all child elements of the specified element,

$ (' #box '). Children ()

3. View all sibling elements

Siblings ()

4, view all parent elements

Parent ()

5,eq (Index)

Finds the first element of a specified element, index is an indexed value

  

The jquery! of inexplicable

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.