How do you know if a second-level parent has a certain class?



  • There's the following code:

    <div class="select form_select">
        <span>Прямая</span>
        <div class="select_list">
            <div>Прямая</div>
            <div>Угловая</div>
            <div>С островом</div>
            <div>П-образная</div>
        </div>
    </div>
    

    It's like a click on daughters. div class block .select_list Find out if the parent has a second level .select Class .form_select?



  • For example:

    $('.select.form_select .select_list > div').on('click', function(){
        if ($(this).parent().parent().hasClass('form_select')) {
            ...
        }
    });
    

    Or so, although it's not as strict as the challenge:

    $('.select.form_select .select_list > div').on('click', function(){
        if ($(this).closest('.form_select').length > 0) {
            ...
        }
    });
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2