English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The add() method adds elements to the existing element group.
The add() method adds elements to the entire document, or if a specificcontextParam,It adds elements only within the context element.
$(selector).add(element, contextParam)
Add <span> element to the existing element group <p> within:
$("document").ready(function(){ $("p").add("span").css("background-color", "lightgreen"); });Test and see‹/›
Add <p> and <span> elements to the existing element group <h2> within:
$("document").ready(function(){ $("h2").add("p").add("span").css("background-color", "lightgreen"); });Test and see‹/›
Add a <p> element to the existing <div> element:
$("button").click(function(){ $("div").add("<p>Hello world</p>").appendTo("div"); });Test and see‹/›
Parameter | Description |
---|---|
element | Specify a selector expression, a jQuery object, one or more elements separated by spaces to be added to the set of matched elements |
contextParam | Optional) Specify the starting point for the selector expression to match in the document |