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