jquery - 如何在jquery中添加当前类选择的div

标签 jquery html css

Codepen Demo

这里我在 jquery 上使用了悬停功能。它工作正常。但我需要在悬停 div 上选择 li

$('.block-templates-container:not(:first-child)').hide();
   $(".block-name").each(function() {
      $(this).hover(function() {    
         $('.block-templates-container').hide();
         var getId = $(this).attr('id');
         $('.block-templates-container#' + getId + '_show').show();    
      });    
    });

当我将鼠标悬停在右侧 block (标题设计、内容设计)时,未选择 li。如何解决这个问题?

最佳答案

尝试在悬停时添加类

  //Sidebar 
  $('.block-templates-container:not(:first-child)').hide();
      $(this).hover(function() {
          $('.block-templates-container').hide();
          var getId = $(this).attr('id');
          $('.block-templates-container#' + getId + '_show').show();

          $('.block-name').not(this).removeClass('current');
          $(this).addClass('current');
      });
  });

关于jquery - 如何在jquery中添加当前类选择的div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37606639/

相关文章:

javascript - 在 jQuery 对话框关闭之前不返回结果?

javascript - Velocity.js。将 {bottom, top} 重置为 "auto"不起作用,它仍然是 "0px"

javascript - 如何将iframe内容复制到div?

javascript - 设置 body.style.fontSize 后 CSS 字体大小不起作用

html - 在固定内联 block 中垂直居中各种内容

javascript - Ember.js 为特定模型 ID 添加 css 类

javascript - 同位素动态排序

html - CSS 背景内部阴影未填充完整背景

html - Bootstrap 3 列内的相对 div 不受尊重

javascript - 单击 li 标签时无法将 css 添加到 li 元素