Método jQuery appendTo()
Exemplo
Insira um elemento <span> no final de cada elemento <p>:
$("button").click(function(){
$("<span>Hello World!</span>").appendTo("p");
});
Definição e uso
O método appendTo() insere elementos HTML no final dos elementos selecionados.
Dica: Para inserir elementos HTML no início dos elementos selecionados, use o método prependTo() .
Sintaxe
$(content).appendTo(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 at the end of the selected elements. |
selector | Required. Specifies on which elements to append the content to |
Experimente você mesmo - Exemplos
Como usar o método appendTo() para inserir um elemento existente no final de cada elemento selecionado.