Metoda jQuery prepend() .

❮ jQuery HTML/CSS metody

Příklad

Vložit obsah na začátek všech prvků <p>:

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

Definice a použití

Metoda prepend() vloží určený obsah na začátek vybraných prvků.

Tip: Chcete-li vložit obsah na konec vybraných prvků, použijte metodu append() .


Syntax

$(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

Zkuste si to sami - příklady


Vložení obsahu pomocí metody prepend().


Pomocí funkce vložíte obsah na začátek vybraných prvků.


❮ jQuery HTML/CSS metody