jQuery add()Methods

jQuery 遍历方法jQuery Traversing Methods

Examples

Add <p> and <span> elements to an existing set of elements (<h1>):

$("h1").add("p").add("span")

Try it Yourself »

Definition and Usage

The add() method adds elements to an existing set of elements.

This method adds elements to the entire document. Ifcontexta parameter is specified, they are added only within the context element.


Syntax

$(selector).add(element,context)

Parameters Description
element Required. Specifies a selector expression, jQuery object, one or more elements, or HTML fragment to be added to an existing set of elements.
context Optional. Specifies where in the document the selector expression begins to match.

实例

More Examples

DOM
Add <span> elements to an existing set of <p> elements by using DOM element references.

HTML Fragment
Use HTML fragments to add <span> elements to existing <p> elements.


jQuery 遍历方法jQuery Traversing Methods

Other Extensions