Divning birinchi bolasi faolligini tekshirish

Agar divimning birinchi bolasi sinfga ega bo'lsa, jQuery bilan tekshirishni xohlayman. Lekin kimdir yordam berishi mumkinligini tushunolmayapmanmi?

Mana mening kodim:

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code">

$(".popup .title:first-child")
if ($this == .active) {
  console.log("class is active");
} else {
  console.log("class is not active");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="popup">
  

  

</div>
</div> </div>

1
Ushbu chekni qachon/qachon ishlatishni xohlaysiz?
qo'shib qo'ydi muallif Adjit, manba
Ushbu chekni qachon/qachon ishlatishni xohlaysiz?
qo'shib qo'ydi muallif Adjit, manba
faqat hasClass dan foydalaning. $ (bu) .hasClass ("faol")
qo'shib qo'ydi muallif A. Lau, manba
faqat hasClass dan foydalaning. $ (bu) .hasClass ("faol")
qo'shib qo'ydi muallif A. Lau, manba

8 javoblar

if ($("div h3:first-child").hasClass(".active")){
 console.log("Class is active");
}
3
qo'shib qo'ydi
Qavsning yo'qolganini tasavvur qiling
qo'shib qo'ydi muallif A. Lau, manba
Bolalarim bor, juda ko'p rahmat ... tezlikni yozib qo'ying! ;)
qo'shib qo'ydi muallif mayersdesign, manba
Zo'r, yordam berishi mumkin bo'lganimdan xursandman
qo'shib qo'ydi muallif mayersdesign, manba
Birinchi " kodi bilan o'zgartirilishi kerak ) Buni amalga oshirish mumkin emas, chunki tahrirlashlar kamida 6 ta belgidan iborat bo'lishi kerak.
qo'shib qo'ydi muallif Lichtbringer, manba
Ishlaganingiz uchun tashakkur!
qo'shib qo'ydi muallif Dave, manba
if ($("div h3:first-child").hasClass(".active")){
 console.log("Class is active");
}
3
qo'shib qo'ydi
Qavsning yo'qolganini tasavvur qiling
qo'shib qo'ydi muallif A. Lau, manba
Bolalarim bor, juda ko'p rahmat ... tezlikni yozib qo'ying! ;)
qo'shib qo'ydi muallif mayersdesign, manba
Zo'r, yordam berishi mumkin bo'lganimdan xursandman
qo'shib qo'ydi muallif mayersdesign, manba
Birinchi " kodi bilan o'zgartirilishi kerak ) Buni amalga oshirish mumkin emas, chunki tahrirlashlar kamida 6 ta belgidan iborat bo'lishi kerak.
qo'shib qo'ydi muallif Lichtbringer, manba
Ishlaganingiz uchun tashakkur!
qo'shib qo'ydi muallif Dave, manba

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code">

// True
console.log( 
    $( ".popup .title" ).first().hasClass('active')
);

// True
console.log( 
    $( ".popup .title:nth-child(1)" ).hasClass('active')
);

// False
console.log( 
    $( ".popup .title:nth-child(2)" ).hasClass('active')
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="popup">


</div>
</div> </div>

0
qo'shib qo'ydi

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code">

// True
console.log( 
    $( ".popup .title" ).first().hasClass('active')
);

// True
console.log( 
    $( ".popup .title:nth-child(1)" ).hasClass('active')
);

// False
console.log( 
    $( ".popup .title:nth-child(2)" ).hasClass('active')
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="popup">


</div>
</div> </div>

0
qo'shib qo'ydi

Bu erda bolaning active classi mavjudligini tekshirishingiz mumkin -

if($(".popup .title:first-child").hasClass('active')){
  console.log("class is active");
} else{
  console.log("class is not active");
}
0
qo'shib qo'ydi

Bu erda bolaning active classi mavjudligini tekshirishingiz mumkin -

if($(".popup .title:first-child").hasClass('active')){
  console.log("class is active");
} else{
  console.log("class is not active");
}
0
qo'shib qo'ydi

jQuery funksiyasi mavjud, hasClass() - elementning sinf mavjudmi yoki yo'qligini tekshirish. Ushbu holatda:

if($(this).hasClass('active')) {
  console.log("class is active");
} else{
  console.log("class is not active");
}

Docs: http://api.jquery.com/hasClass/

0
qo'shib qo'ydi

jQuery funksiyasi mavjud, hasClass() - elementning sinf mavjudmi yoki yo'qligini tekshirish. Ushbu holatda:

if($(this).hasClass('active')) {
  console.log("class is active");
} else{
  console.log("class is not active");
}

Docs: http://api.jquery.com/hasClass/

0
qo'shib qo'ydi
Javascript UZB
Javascript UZB
99 ishtirokchilar

@js_uzb @vuejs_uz @react_uz @nodejs_uz @angular_uz @ngTashkent @yiiframework_uz @laravel_uz @linux_uzbek @python_uz @swift_uzb —————— @uzdevgroup @UzGeeksGroup ——— @UzDev_Jobs @jobs_uzb