Método jQuery appendTo()
Ejemplo
Inserte un elemento <span> al final de cada elemento <p>:
$("button").click(function(){
$("<span>Hello World!</span>").appendTo("p");
});
Definición y uso
El método appendTo() inserta elementos HTML al final de los elementos seleccionados.
Sugerencia: para insertar elementos HTML al principio de los elementos seleccionados, utilice el método prependTo() .
Sintaxis
$(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 |
Pruébelo usted mismo - Ejemplos
Cómo utilizar el método appendTo() para insertar un elemento existente al final de cada elemento seleccionado.