Metoda replaceAll

Metoda replaceAll zëvendëson disa elemente me të tjerë. Ajo funksionon në mënyrë të ngjashme me metodën replaceWith.

Sintaksa

Parametri i metodës mund të jetë tekst (mundësisht me tagje), array, element DOM ose objekt jQuery:

javascript$(elements).replaceWith(elements);

Shembull

Le t'i zëvendësojmë të gjitha paragrafët me klasën www me një div me tekstin '!!!':

html<p class="www">text</p>
<p class="www">text</p>
<p class="www">text</p>
<p>text</p>
javascript$('<div>!!!</div>').replaceAll('p.www');

Kodi HTML do të duket kështu:

html<div>!!!</div>
<div>!!!</div>
<div>!!!</div>
<p>text</p>

Shihni gjithashtu

  • metoda replaceWith,
    e cila gjithashtu zëvendëson disa elemente me të tjerë