|
.addParent( "Parent_Tag_Name" [, Properties ] [, Position ] ) - Add a Parent element
.addParent() will append a parent element to a child. It can set attributes to the parent using the Properties parameter. Parents can be attached more than one level up from the target element using position parameter.
Parameters
Returns
Example 1
Clicking on "Add Parent" button will add a parent div element to #child.
JS
HTML
CSS
$.domLoaded(function() {
$.get("#add").on("click", function() {
//add a parent div to #child
$.get("#child").addParent("div", {
"class" : "parent",
"text" : "Parent"
});
});
});
Result
Example 2
Adding a parent div to the #parent using #child DOM functionality. This can be applied any available level up in the DOM structure.
JS
HTML
CSS
$.domLoaded(function() {
$.get("#add").on("click", function() {
//add a div parent to #parent using #child DOM
$.get("#child").addParent("div", {
"class" : "new",
"text" : "New Parent"
}, 1 );
});
});
Result
| |||||||||||||||||||||||||||
