jQuery before () method
Examples
Insert content before each <p> element:
$("button").click(function(){
$("p").before("<p>Hello world!</p>");
});
$("p").before("<p>Hello world!</p>");
});
try it"
Definition and Usage
before () method before the selected element into the specified content.
Tip: To insert content after the selected element, use after () method.
grammar
$(selector).before(content,function(index))
参数 | 描述 |
---|---|
content | 规定要插入的内容(可包含 HTML 标签)。
可能的值:
|
function(index) | 可选。规定返回待插入内容的函数。
|
More examples
before () - Create content via HTML, jQuery and DOM
() Method to insert content through before.
Use function Inserts
How to use the function before the selected element insertions.