jquery Handy notes on the common jquery operations DOM event _jquery

Source: Internet
Author: User
Tags object model

The DOM is the abbreviation for Document Object model, meaning the documentation objects models. Dom is a browser, platform, language-independent interface that makes it easy to access all the standard components in a page.

Dom operations can be divided into three dimensions, namely, the DOM core (core), Htm-dom, and Css-dom.

JQuery DOM Element method

function Description
. Get () Gets the DOM element specified by the selector.
. Index () Returns the index position of the specified element relative to the other specified element.
. Size () Returns the number of elements that are matched by the jQuery selector.
. ToArray () Returns the element that the JQuery selector matches as an array.

1.attr (). Removeattr ()

The. attr () method can pass in a parameter of a name-value pair, or it can pass in an object parameter that contains more than 2 name-value pairs, for example:

. attr (' src ', ' images/a.jpg ');

. attr ({
 rel: ' www ',
 ID: ' ZZ ',
 title: ' Some ',
 some: '} '
);

Of course, you can remove one or more attributes. Removeattr (' id rel ');

2.prop ()

This method can get the property value

The name of the property (string), such as. prop (' id '), passed in the value you want to get.

Set the value of the ID (modify the properties of the DOM itself, such as the Href,id of a label)
. Prop (' id ', ' otherid ');

3.val ()

This method is often used to get the value of a form control

4.insertBefore (). InsertAfter (). Prependto (). Appendto ()

. InsertBefore () to add content outside of existing elements, (reverse action. Before ())
. InsertAfter () to add content outside of existing elements, after (reverse action. After ())
. prependto () Add content to the existing element, (reverse action. prepend ())
. Appendto () adds content inside and after existing elements; append ()

5.clone ()

The method can copy the copy element, and if the element that needs to be copied inherits other events, it needs to pass in a Boolean value as an argument. Clone (True)

6.wrap (). Wrapall (). Wrapinner ()

. Wrap () and. Wrapinner () can be understood as relative,. Wrap () is a layer outside the element, and. Wrapwith () is a layer inside the element,

and. Wrapall () is wrapped around all the elements that are matched to

7.html (). Text (). ReplaceWith (). ReplaceAll ()

. HTML () can pass in text or DOM nodes;

. Text () can only read or replace texts;

ReplaceWith () put ... Replace "Cheng" ...;

ReplaceAll () put ... Replace "Give" ...

8.empty ()

removing elements from

9.detach (). Remove ()

These 2 methods are somewhat similar and do not remove the matching elements from the jquery object, but there are differences:

. Detach () All bound events, additional data, etc. will be preserved

. Remove () In addition to the element itself to be retained, others such as
Bound events, additional data, etc. will be removed.

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.