如何访问'this'和我一起工作的人

How do I access the elements that are inside the 'this' that I am currently working with?

本文关键字:一起 工作 this 访问 何访问      更新时间:2023-09-26

如何访问当前正在处理的'this'内部的元素?

以下是我目前正在使用的HTML代码。

<div class="expander" id="edu">educational qualifications
             <ul class="list">
                 <li>bachelor's in cs</li>
                 <li><div  class="expander">master's in machine learning
                     <ul class="list" id="edu1">
                         <li>authored the famous paper on giving a shit</li>
                         <li>co-authored several other papers</li>
                     </ul></div>
                 </li>
                 <li><div class="expander">phd in visual intelligence
                     <ul class="list">
                         <li>watch and learn</li>
                         <li>haha.</li>
                     </ul></div>
                 </li>
                 <li>cleared jee mains</li>
                 <li>cleared cbse aissce</li>
             </ul></div>

我正在用我新发现的Javascript知识做实验,我想让所有的项目符号都隐藏起来,直到我在它们的标题上方徘徊。我尝试使用以下javascript代码:

$(document).ready(function() {
$('li ul').hide();
$('.expander').mouseenter(function(){
    $(this + 'ul').fadeIn('fast');
}); });

我不能使它工作。

如何访问当前正在处理的'this'内部的元素?

try this -

$('ul',this).fadeIn('fast');

编辑 -

$('.expander ul').hide();
$('.expander').mouseenter(function () {
    $('ul:first',this).fadeIn('fast');
});

Demo -> http://jsfiddle.net/mohammadAdil/jahR6/

变量#1:

$('ul', this).fadeIn('fast');

变体# 2:

$(this).find('ul').fadeIn('fast');

Try

$(this).find('ul').fadeIn('fast');