简体   繁体   English

在列表项上显示隐藏的div

[英]show hidden div on list items

html: 的HTML:

I have a ul list with each li counstructed like this: 我有一个ul列表,每个li都像这样:

   <li class="A">list-item
     <div>1</div>
     <div class="B">2
        <div class="C">3</div>
     </div>

   </li>

where div C has css property display:none; 其中div C具有CSS属性display:none; I wrote this js: 我写了这个js:

   $(".A").hover(function () {
   $(".C").toggle();
   });

that shows hidden divs on li hover, but I would like js working only on active li item. ,它显示了li悬停时的隐藏div,但是我希望js仅在活动li项上工作。 So when i hover li item it shows only that list item hidden div. 因此,当我将鼠标悬停在li项目上时,它仅显示该列表项目隐藏的div。

any suggestions? 有什么建议么? I am new with js, so any help would be appreciated, thnx! 我是js的新手,所以任何帮助,谢谢!

Try something like this, it will find class C within this (which will be the element being hovered) 尝试这样的事情,它会找到类Cthis (将在该元件徘徊)

$(".A").hover(function() {
    $(this).find(".C").toggle();
});

Use context to narrow the lookup to the desired element's children. 使用上下文将查找范围缩小到所需元素的子级。

$(".A").hover(function () {
   $(".C", this).toggle();
});

Using the hover() , the correct format of hover function is: 使用hover()hover函数的正确格式为:

$(".A").hover(
  function () {
    // A function to execute when the mouse pointer enters the element.
    $(this).find(".C").show();
  },
  function () {
    // A function to execute when the mouse pointer leaves the element.
    $(this).find(".C").hide();
  }
);

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

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