Phương thức jQuery insertAfter ()
❮ Phương thức HTML / CSS jQuery
Thí dụ
Chèn một phần tử <span> sau mỗi phần tử <p>:
$("button").click(function(){
$("<span>Hello world!</span>").insertAfter("p");
});
Định nghĩa và Cách sử dụng
Phương thức insertAfter () chèn các phần tử HTML sau các phần tử đã chọn.
Mẹo: Để chèn các phần tử HTML trước các phần tử đã chọn, hãy sử dụng phương thức insertBefore () .
Cú pháp
$(content).insertAfter(selector)
Parameter | Description |
---|---|
content | Required. Specifies the content to insert (must contain HTML tags). Note: If content is an existing element, it will be moved from its current position, and inserted after the selected elements. |
selector | Required. Specifies where to insert the content |
Hãy tự mình thử - Ví dụ
Cách sử dụng phương thức insertAfter () để chèn một phần tử hiện có vào sau mỗi phần tử được chọn.
❮ Phương thức HTML / CSS jQuery