Basic jquery and basic jquery tutorials

Source: Internet
Author: User

Basic jquery and basic jquery tutorials

 

I. Basic selector:


ID selector: $ ("# id name ")
For example: $ ("# div1" ).css ("width", "100px ");
CLASS selector: $ (". id name ")
Coordinate $ ("# id name, # id name ")
Descendant $ ("# id name ")
Ii. Filter Selector

First: $ (". id name: first ")
Last: $ (". id name: last ")
Any one: $ (". id name"). eq (index number) or $ (". id name: eq (Index Number )")
Greater than: $ (". id name: gt (Index Number )")
Less than: $ (". id name: lt (Index Number )")
Not equal to: $ (". id name: not (Index Number )")
Odd: $ (". id name: odd ")
3. Content Filtering


Even number: $ (". id name: even ")
Attribute name: $ (". id name [attribute name]")
Operation of attribute name: $ (". id name [attribute name]" ).css ("width", "100px ");
Content Filtering: $ (". id name: contains ('string ')")
Child element: $ (". id name: has ('child element '))


Event:

General events: Remove on
Composite event:

Hover: hover (function () {}, function (){});

 

: Toggle (function () {}, function (){}......);

 

Bubble event:

Five divs are nested in sequence

Effect:

Event: Click the pop-up id name

In this way, the smallest div is clicked, And the id names of all div

Solution: return false

DOM operation:

Operation attributes, methods, and styles

Attribute

 

 

 

First: click the button to hide txt1. Second, click the button to query the background color of txt1 and change the background color of Button 2.

Operation form elements:

 

Value: var d = $ ("selector"). val () Value: $ ("selector"). val ("value ")

Non-form elements:

Valid values: $ ("selector" ).html ("content"), $ ("selector"). text ("content ")

Value assignment: var s = $ ("selector" Contents .html ("content"), var s = $ ("selector"). text ()

 

Operation-related elements

1. Search

Parent level:

Add a parent () to the parent level ()

Select a parent level:. parents ("# id ")

Child level: children ()

Brother/level:

 

Brother: prev ()

Prevall (selector)

Younger brother: next ()

Nextall (selector)

 

Ii. Operations

New: $ ("HTML string ")

Add: appen (jquery object) Internal add

After (,...) added at the lower level

Before ("...") upper level

Remove:

Empty () clears all internal elements

Remove () remove an element

 

 

NOTE: If js is not written at the end, $ (document). ready (function () {write here}) must be added at the beginning });

 

Related Article

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.