jquery Tutorial Examples and demo 3

Source: Internet
Author: User
Tags add filter array object contains empty expression string

Remove () Delete matching objects
Note distinguish empty (), empty () Remove the child nodes of the matching object, remove (), and remove the matching object
Wrap (HTM) to include matching objects in the given HTML code

test paragraph.

jQuery

jquery Code and functionality:

function JQ () {
$ ("P"). Wrap ("
");
}

Executed after the equivalent

test paragraph.

Wrap (Elem) includes the matching object in the given object's jquery code and functionality:

test paragraph.


jQuery function jq () {
$ ("P"). Wrap (document.getElementById (' content '));
}

Executed after the equivalent

test paragraph.


Traversing, combining
Add (expr) on the basis of the original object in addition to the jquery object that matches the specified expression

hello

hello again


jQuery

jquery Code and functionality:

function JQ () {
var f=$ ("P"). Add ("span");
for (Var i=0;i < $ (f). Size (); i++) {
Alert ($ (f). EQ (i). html ());
}

Execute $ ("P") to get a match

object, there are two, add ("span") is based on ("P") with a matching object, all a total of 3, from the above function run results can see $ ("P"). Add ("Span" ) is a collection of 3 objects, respectively, [

hello

],[

hello again

],[ Hello Again].

Add (EL) attaches the specified DOM element based on the matching object.
$ ("P"). Add (document.getElementById ("a"));

Add (ELS) on a matching object based on the specified set of objects, Els is an array.

hello

hello again

jquery Code and functionality:

function JQ () {
var f=$ ("P"). Add ([document.getElementById ("a"), document.getElementById ("B")])
for (Var i=0;i < $ (f). Size (); i++) {
Alert ($ (f). EQ (i). html ());
}

Note that the ELS is an array, where the [] cannot be omitted.
Ancestors () in turn, the contents of the parent node of the matching nodes are objects, except for the root node (a bit difficult to understand, see the following example)


one



two

jquery Code and functionality:

function JQ () {
var f= $ ("U"). Ancestors ();
for (Var i=0;i < $ (f). Size (); i++) {
Alert ($ (f). EQ (i). html ());
}

The first object is the content of the parent node of , [two]
The first object is the content of the parent node (DIV) of the parent node,[

one

two]
A general document also has and

Ancestors (expr) takes an object that conforms to an expression based on the ancestors ()
As in each example, Var f is changed to Var f= $ ("U"). Ancestors ("div"), only one object is returned:
[

one

two]

Children () returns the Transposon mediated point of the matched object

one



two

jquery Code and functionality:

function JQ () {
Alert ($ ("#ch"). Children (). HTML ());
}

$ ("#ch"). Children () Gets the object [two]. So the result of HTML () is "two"
Children (expr) returns the node in the Transposon mediated point of the matched object that conforms to the expression


two
three

jquery Code and functionality

function JQ () {
Alert ($ ("#ch"). Children ("#sp"). html ());
}

$ ("#ch"). Children () Gets the object [twothree].
$ ("#ch"). Children ("#sp") filtered by [three]
Parent () parent (expr) takes a match to the node of the object. Reference children help understand
Contains (str) returns the object containing the string str in the matched object

this is just a test.

so is this

jquery Code and functionality:

function JQ () {
Alert ($ ("P"). Contains ("Test"). html ());
}

$ ("P") gets two objects, and contains only one string "test". All $ ("P"). Contains ("Test") returns [

this is just a test.

]

End () to return to the state before the operation on the matching elements list.
Filter (EXPRS) filters realistic objects that match an expression Exprs an array, and note that adding "[]"

hello

hello again

and again

jquery Code and functionality:

function JQ () {
Alert ($ ("P"). Filter (". Selected"). html ())
}

$ ("P") gets three objects, $ ("P"). Contains ("Test") returns only the object with class selected.
Find (expr) to continue finding objects that match an expression in a matching object

hello

hello again

and again

Query code and Features:

function JQ () {
Alert ($ ("P"). Find ("#a"). HTML ()
}

Look for an object with ID A in the $ ("P") object.
Is (expr) determines whether an object conforms to an expression and returns a Boolen value

hello

hello again

and again

Query code and Features:

function JQ () {
Alert ($ ("#a"). Is ("P"));
}

Whether the $ ("#a") conforms to the jquery expression.
We can use $ ("#a"). Is ("div"); ("#a"). Is ("#a") test more
Next () Next (expr) returns the remaining sibling nodes of the matching object

hello

hello again

and again

jquery Code and functionality

function JQ () {
Alert ($ ("P"). Next (). html ());
Alert ($ ("P"). Next (". Selected"). html ());
}

$ ("P"). Next () returns [

hello again

,

and again

] two objects
$ ("P"). Next (". Selected)" returns only [

and again

] an object
Prev () prev (expr) in reference to next understanding

Not (EL) (expr) moves a matching object from a jquery object, El is a DOM element, and expr is a jquery expression.

one

two


jQuery

JQuery Code and functionality:

Function js () {
      alert ($ ("P"). Not (document.getElementById ("a")). html ();
      Alert ($ ("P"). Not ("#a"). html ());
}

$ ("P") consists of two objects, the excluded object is [

one

]
siblings () siblings (expr) jquery matches other sibling-level objects in the object

one



  

TWO



jQuery

JQuery code and functionality:

function js () {
        alert ( "Div"). Siblings (). EQ (1). html ()); The result of
}

$ ("div"). Siblings () returns two objects [

one

,jQuery]
Alert ($ (" Div "). Siblings (" a ") returns an Object [jQuery]



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.