jQuery before() Methode

❮ jQuery HTML/CSS-methoden

Voorbeeld

Voeg inhoud in voor elk <p> element:

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

Definitie en gebruik

De methode before() voegt gespecificeerde inhoud in voor (vóór) de geselecteerde elementen.

Tip:   Gebruik de methode after() om inhoud in te voegen na geselecteerde elementen.


Syntaxis

$(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 het zelf - Voorbeelden


Voeg inhoud in met de before() methode.


Een functie gebruiken om inhoud in te voegen vóór geselecteerde elementen.


❮ jQuery HTML/CSS-methoden