【问题标题】:aria-expanded="true" doesn't add class to parentaria-expanded="true" 不向父级添加类
【发布时间】:2018-10-20 04:22:50
【问题描述】:

当折叠链接具有 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>

和 jquery

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

我还试图通过将 .info-title[aria-expanded="true"] 更改为 a[aria-expanded="true"] 并最接近父母来使其工作,但它没有工作。

【问题讨论】:

  • 在 OP 中值为 false
  • @guradio 感谢您为我指出这一点。

标签: javascript jquery


【解决方案1】:

由于它是一个引导折叠目标,默认情况下女巫具有 aria-expanded="false" 并在单击它后将值更改为 true 我需要将我的 js 代码更改为:

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

希望这对将来的某人有所帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-05
    • 1970-01-01
    • 2016-09-05
    • 2019-02-10
    • 2017-02-17
    相关资源
    最近更新 更多