65 of 119 menu

The addBack method

The addBack method adds elements from the previous set to the current one (we are talking about one method chain), a selector can also be selectively passed to the method. The previous set is the set of elements that can be obtained using the end method.

Syntax

.addBack([selector]);

Example

Let's find the paragraph with #test, then find the parent of that paragraph with parent, append the found paragraph to its parent with addBack, and prepend it with the text '!' with prepend. This will result in both the paragraph and its parent having the text '!' at the beginning:

<div> <p>text</p> <p id="test">text</p> <p>text</p> </div> $('p').parent().addBack().prepend('!');

HTML the code will look like this:

<div> ! <p>!text</p> <p id="test">!text</p> <p>!text</p> </div>

See also

  • method add,
    which adds the given elements to a set
  • method end,
    which returns the previous set of elements in the current method chain
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