Metoda jQuery before() .

❮ jQuery HTML/CSS metody

Příklad

Vložit obsah před každý prvek <p>:

$("button").click(function(){
  $("p").before("<p>Hello world!</p>");
});

Definice a použití

Metoda before() vloží určený obsah před (před) vybrané prvky.

Tip:   Chcete-li vložit obsah za vybrané prvky, použijte metodu after() .


Syntax

$(selector).before(content,function(index))

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

Possible values:

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

Zkuste si to sami - příklady


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


Jak používat funkci k vložení obsahu před vybrané prvky.


❮ jQuery HTML/CSS metody