jQuery before() Metode

❮ jQuery HTML/CSS-metodes

Voorbeeld

Voeg inhoud voor elke <p>-element in:

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

Definisie en gebruik

Die before() metode voeg gespesifiseerde inhoud voor (voor) die geselekteerde elemente in.

Wenk:   Om inhoud na geselekteerde elemente in te voeg, gebruik die after() metode.


Sintaksis

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

Probeer dit self - voorbeelde


Voeg inhoud in met die before() metode.


Hoe om 'n funksie te gebruik om inhoud voor geselekteerde elemente in te voeg.


❮ jQuery HTML/CSS-metodes