简体   繁体   English

aria-expanded =“ true”不会将类添加到父项

[英]aria-expanded=“true” doesn't add class to parent

I'm trying to add a class to my parent div when the collapse link has aria-expanded="true", but nothing is happening. 当折叠链接具有aria-expanded =“ true”时,我正在尝试向父div添加一个类,但是什么也没有发生。

<div class="info-tab col-xl-3">
          <div class="info-img">
            <?php the_post_thumbnail(); ?>
          </div><!-- .news_img -->
          <a data-toggle="collapse" href="#collapse-<?php the_ID(); ?>" class="info-title" role="button" aria-expanded="false" aria-controls="collapse-<?php the_ID(); ?>">
            <?php the_title(); ?>
          </a>
        </div>

and the jquery 和jQuery

  jQuery(function($){
$(function() {
  $('.info-title[aria-expanded="true"]').closest('.info-tab').addClass('no-border');
});
});

i was also trying to get it work by changing the .info-title[aria-expanded="true"] to a[aria-expanded="true"] and closest to parents but it didn't work. 我还试图通过将.info-title [aria-expanded =“ true”]更改为a [aria-expanded =“ true”]并使其最接近父母来使其正常工作,但是它没有用。

Since it is a bootstrap collapse target witch by default has aria-expanded="false" and changes the value to true after clicking on it I needed to change my js code to: 由于默认情况下它是一个引导崩溃目标,女巫具有aria-expanded =“ false”并在单击它后将其值更改为true,所以我需要将js代码更改为:

jQuery(function($){
 $( ".info-title" ).click(function() {
  $( this ).closest('.info-tab').toggleClass('no-border');
 }); 
});

hope this helps someone in the future 希望这对以后的人有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM