How to create, modify, and add the DOM element _ jQuery

Source: Internet
Author: User
This article describes how to create, modify, and add DOM elements in jQuery. If you need them, you can refer to how to operate DOM elements in one go on the fly?

For example, you can perform the create action> modify action> Add action in sequence.

Because jQuery supports chained operations, it is actually the builder mode of the design mode, so we can execute three operation strings together.

First, create a p element. The content contains an a element.

The Code is as follows:


$ ('

JQuery

')


Then add an href attribute for element.

The Code is as follows:


$ ('

JQuery

'). Find ('A'). attr ('href', 'HTTP: // www.jquery.com ')


Finally, add the newly added p element to the body.

The Code is as follows:


$ ('

JQuery

'). Find ('A'). attr ('href', 'HTTP: // www.jquery.com '). end (). appendTo ('body ')


Note: The end () operation must be performed here. Otherwise, the element added to the body is not the element of the p element.

In fact, the end () operation cannot be equivalent to the Undo operation. It returns the previous selection, but this selection has been modified by the operation before the end.

The Code is as follows:








Related Article

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.