jquery Tutorial Examples and demo 2

Source: Internet
Author: User
Tags object copy empty execution insert
Tutorials | sample |jquery DOM Operations
Property
We take As an example, in the original JavaScript can use Var O=document.getelementbyid (' a ') to take the ID of a node object, When you use O.SRC to get or modify the SCR properties of the node, in jquery $ ("#a") will get the jquery object [], which can then be manipulated in many ways that jquery provides, such as $ ("# A "). SCR () will get 5.jpg,$ (" #a "). SCR (" 1.jpg ") changes the object Src property to 1,jpg. Here's a list of the many jquery methods that jquery offers to make it easy to manipulate DOM objects quickly
Herf () Herf (Val)
Description: Herf the jquery object properties.
Example:
No jQuery before jQuery

jquery Code and functionality:

function JQ () {
Alert ($ ("#test"). href ());
$ ("#test"). href ("2.html");
}

Run: First pop-up dialog box to display the connection URL with ID test, change its URL to 2.html, when the pop-up dialog will see the switch to 2.html
In the same way, jquery offers a similar alternative, and you can experiment with each:
Herf () Herf (val) HTML () HTML (val) ID () ID (val) name () name (val) rel () rel (val)
SRC () src (val) title () title (Val) Val () Val (Val)
Operation
After (HTML) inserts a section of HTML jquery code and functionality after the matching element:
Append (HTML) inserts the specified HTML jquery code and functionality at the end of the matching element:

jQuery function JQ () {
$ ("#test"). After ("Hello");
}

After execution is equivalent to:

jQueryHello

After (Elem) after (elems) inserts the specified object Elem or object group elems into the matching element

after

jQuery

jquery Code and functionality

function JQ () {
$ ("a"). After ($ ("#test"));
}

Executed after the equivalent

jquery

after

jQuery function JQ () {
$ ("#test"). Append ("Hello");
}

Executed after the equivalent

jQueryHello

Similarly there are append (elem) append (Elems) before (HTML) before (Elem) before (Elems) please perform the Append test and understand the callers and after.

appendto (expr) is the opposite of append (Elem) Clone () copy a jquery object empty () Delete all child nodes of the matching object

after

jQuery

jquery Code and functionality

function JQ () {
$ ("a"). Appendto ($ ("#test"));
}

Executed after the equivalent

afterjQuery

after

jQuery

jquery Code and functionality:

function JQ () {
$ ("#test"). Clone (). Appendto ($ ("a"));
}

Copy $ ("#test") and insert into after execution equivalent to

after

jquery

after


span

after



jQuery

jquery Code and functionality:

function JQ () {
$ ("#test"). empty ();
}

Executed after the equivalent

jQuery


InsertAfter (expr) insertbefore (expr)
According to the official explanations and my few simple tests InsertAfter (expr) are equivalent to before (Elem), insertbefore (expr) equals after (Elem)
Prepend (HTML) prepend (elem) prepend (Elems) is inside of the matching element and begins to insert
Differentiate append (elem) appendto (expr) prepend (Elem) by the following example

p


div

Execute $("#a"). Append ($ ("div")) after the equivalent


P

div

Execute $ ("#a"). Appendto ($ ("div")) after the equivalent


Div

p


Execute $ ("#a"). Prepend ($ ("div")) after the equivalent


div

P



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.