JQuery learning, jquery

Source: Internet
Author: User

JQuery learning, jquery
Control page control element content and value operation element content operation text content

Text () gets the text content of all matching elements

Text (val) sets the text content of all matching elements

<Div> <span> test </span> </div>... $ ("div"). text (); // obtain the text content of the div Element



Operate HTML content

Html () obtains the HTML content of the First Matching Element.

Html (val) sets HTML content that matches all elements

<div><span>test</span></div>...$("div").html();

Operation element value

Var () gets the current value of the First Matching Element and returns a string or array.

$ ("# Le"). val (); // obtain the value of the element with the id of le.


Var (val) sets the values of all matching elements

$ ("Input: text"). val ("new"); // set the value for all text boxes


Var ([]) is used to set values for radio and other elements.

$ ("Select"). val (['list item 1', 'list item 2', 'list item 3']);

Operate DOM nodes

Search nodes


Create a node

<Script language = "javascript"> $ (document ). ready (function () {var $ p = $ ("<p> </p>"); // create a node. p.html ("<span style = 'color: # FF0000 '> Add </span> "); // reset the HTML content of <div> $ (" body "). append ($ p); // creates a new paragraph node in the body });


Insert a node into a node



Insert external nodes



Delete, copy, and replace nodes

Empty ()

Remove ()

Differences

$ (Document ). ready (function () {$ ("# div1 "). empty (); // Delete All subnodes of div1 $ ("# div2 "). remove (); // delete a node with the id of div2 });

Copy a node

Clone ()

$ (Function () {$ ("input "). bind ("click", function () {// bind to button click event $ (this ). clone (true ). insertAfter (this); // copy yourself and event handling });});

Replace Node

ReplaceAll ()

RepalceWith (content)

<Script language = "javascript"> $ (document ). ready (function () {$ ("# div1 "). replacewith ("<div> replacewith () Replacement result </div>"); $ ("<div> replaceAll () Replacement result </div> "). replaceAll ("# div2") ;}); </script>

Operate CSS styles

Modify CSS class implementation


Eg

$ ("Div"). addClass ("yellow red"); // Add the yellow and red CSS classes to all div elements.


CSS style modification implementation














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.