jquery Learning-attribute access, inserting nodes

Source: Internet
Author: User

//Property access
$ (function () {//1. Manipulating text nodes: the text () method of the JQuery objectAlert ($ ("#bj"). text ()); $ ("#bj"). Text ("123")//2. Action attribute node: the attr () method of the JQuery object.//Note: Direct manipulation of the value property values can be done using the more convenient Val () method.Alert ($ (": Text[name= ' username ']"). attr ("value")); $ (: Text[name='username']). attr ("value","123");})

Inserting nodes

The test uses jquery to create the node and insert the node into the specified node

1. Create nodes: You can use the $ (HTML) method, element nodes, text nodes, and attribute nodes

$ (function () {//1. Create a <li id= ' id1 ' > Chongqing </li>//2. And add it to the #city sub-node$("<li id= ' id1 ' > Chongqing </li>"). AppendTo ($ ("#city"));$("#city"). Append ("<li id= ' id1 ' >[Chongqing]</li>")$("<li id= ' id1 ' > Chongqing </li>"). Prependto ($ ("#city"));$("#city"). Perpend ("<li id= ' id1 ' >[Chongqing]</li>") alert ($ ("#id1"). Text ())})

2. Inserting nodes

1. Create a <li id= "Id1" > Chongqing </li>

2. and add it to the back of #bj

$ ("<li id = ' ID1 ' > Chongqing </li>"). InsertAfter ($ ("#bj"))

$ ("#bj"). After ("<li id= ' id1 ' > Chongqing </li>");

Add in front

$ ("<li id = ' ID1 ' > Chongqing </li>"). InsertBefore ($ ("#bj"))

$ ("#bj"). Before ("<li id= ' id1 ' > Chongqing </li>");

jquery Learning-attribute access, inserting nodes

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.