19 of 119 menu

The insertBefore method

The insertBefore method adds text before the given element. There is also a before method that works in a similar way.

Syntax

Insert text before an element:

$(text).insertBefore(selector);

The content can be not only plain text, but also a DOM element, selector, array of elements, string or jQuery object.

Example

Let's insert text with tags before the given paragraph:

<p id="test">paragraph indent indention indentation indenture rubric</p> $('<p>!!!</p>').insertBefore('#test');

HTML the code will look like this:

<p>!!!</p><p id="test">paragraph indent indention indentation indenture rubric</p>

See also

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline