Metod contents

Metod contents elementleriň nesillerini, şol sanda tekstleri we teswirleri hem alyar.

Sintaksis

Metod parametrleri kabul etmeýär:

javascript.contents();

Metod contents metoda meňzeýär children, park nesilleriniň tekstine giriş synanyşyklarynda görkezilýär. Aşakdaky iki mysaly deňeşdiriň:

Mysal

Metody children ulanyň:

html<p id="test">tekst1 <b>gally</b> tekst2</p>
javascript$('#test').children().each(
  function() {
    console.log($(this).text()); // 'gally' çykarar
  }
);

Mysal

Metody contents ulanyň:

html<p id="test">tekst1 <b>gally</b> tekst2</p>
javascript$('#test').contents().each(
  function() {
    console.log($(this).text()); // 'tekst1', 'gally', 'tekst2' çykarar
  }
);

Hem-de görüň

  • metod children,
    elementiň nesillerini alyp biler
  • metod parent,
    elementiň ýakyn ata-enesini alyp biler
  • metod parents,
    elementiň ähli ata-enelerini alyp biler
  • metod closest,
    selektor bilen şertleri kanagatlandyrýan iň ýakyn ata-ene elementini alyp biler