AnswerBun.com

Detect if Class has an element inside of certain Class?

Stack Overflow Asked by ohval on November 17, 2021

I’m trying to get an Alert if a class contains an element of a certain class.

My attempt: https://jsfiddle.net/d9qecgjx/1/

HTML

<div class="parent">

  <div class = "child1">
  </div>
  
  <div class = "child2">
  </div>
  
  <div class = "child3">
  </div>
  
  <div class = "child4">
  </div>

</div>

jQuery

if ( $( ".parent" ).hasClass( ".child3" ) ){
                alert("You have that");
}

One Answer

One approach is to use .find() - it searches descendants. so

if ( $( ".parent" ).find( ".child3" ).length ){
                alert("You have that");
}

Answered by Nikkorian on November 17, 2021

Add your own answers!

Related Questions

Seperate strings with regex and panda

1  Asked on January 11, 2021 by sara-daniel

         

Login into SAP using admin user fails

1  Asked on January 11, 2021 by gram77

 

Using LIKE with multiple columns in a table

3  Asked on January 10, 2021 by soldfor

   

Does the value of global variable persist in multiple API calls

2  Asked on January 10, 2021 by shubroto-shuvo

 

React Component not rendering to HTML

1  Asked on January 10, 2021 by red-apple

     

How can I count a pandas dataframe over duplications

4  Asked on January 10, 2021 by toby-chamberlain

     

javascript .eval() gives me undifined

2  Asked on January 10, 2021 by nourza

     

Loop for column names in python

3  Asked on January 10, 2021 by essegn

         

Return array of values from object based on array

2  Asked on January 9, 2021 by user4584963

         

How do I get out of ‘screen’ without typing ‘exit’?

5  Asked on January 9, 2021 by meder-omuraliev

   

How can I regroup ‘sublists’ in a list with Python?

2  Asked on January 9, 2021 by zhengrong

       

Ask a Question

Get help from others!

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP