English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
the before() method to insert specified content before the selected element.
To insert content after the selected element, please useafter()Method.
Inserting content:
$("selector").before(content)
Inserting content using a function:
$("selector").before(function(index))
Inserting content before each paragraph:
$("button").click(function(){ $("p").before("<p>Hello world</p>"); });Test see‹/›
Inserting content using a function:
$("button").click(function(){ $("p").before(function(i){ return "<p>This p's index: " + i + ".</p>"; }); });Test see‹/›
Parameter | Description |
---|---|
content | Specify the content to be inserted before each selected element (can include HTML tags) Possible values:
|
function(index) | Specify a function that returns the content to be inserted
|