Método jQuery prepend()

❮ Métodos jQuery HTML/CSS

Ejemplo

Inserte contenido al principio de todos los elementos <p>:

$("button").click(function(){
  $("p").prepend("<b>Prepended text</b>");
});

Definición y uso

El método prepend() inserta contenido específico al principio de los elementos seleccionados.

Sugerencia: para insertar contenido al final de los elementos seleccionados, utilice el método append() .


Sintaxis

$(selector).prepend(content,function(index,html))

Parameter Description
content Required. Specifies the content to insert (can contain HTML tags)

Possible values:

  • HTML elements
  • jQuery objects
  • DOM elements
function(index,html) Optional. Specifies a function that returns the content to insert
  • index - Returns the index position of the element in the set
  • html - Returns the current HTML of the selected element

Pruébelo usted mismo - Ejemplos


Inserta contenido con el método prepend().


Usar una función para insertar contenido al principio de los elementos seleccionados.


❮ Métodos jQuery HTML/CSS