jQuery appendTo () method
Examples
Insert <span> element at the end of each <p> element:
$("button").click(function(){
$("<span>Hello World!</span>").appendTo("p");
});
$("<span>Hello World!</span>").appendTo("p");
});
try it"
Definition and Usage
appendTo () method to insert HTML elements at the end of the selected element.
Tip: To insert HTML elements at the beginning of the selected element, use prependTo () method.
grammar
$(content).appendTo(selector)
参数 | 描述 |
---|---|
content | 必需。规定要插入的内容(必须包含 HTML 标签)。 注意:如果content是已存在的元素,它将从当前位置被移除,并在被选元素的结尾被插入。 |
selector | 必需。规定把内容追加到哪个元素上。 |
More examples
Insert existing elements
How to use existing elements appendTo () method to insert at the end of each of the selected element.