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: