查找并删除课程

Jav*_*ter 0 javascript jquery

我有以下结构:

<li id="0" class="instruction">
        <div class="row1">
            title
        </div>
        <div class="row2 details hidden">
            details
        </div>
    </li>
Run Code Online (Sandbox Code Playgroud)

隐藏的CSS是: display: none

我想当用户单击说明时,然后显示详细信息div。

$(document).ready(function () {
        $(".instruction").click(function(e){

            $(e).find('.details').removeClass("hidden");


        });
    });
Run Code Online (Sandbox Code Playgroud)

试图实现类似上面的内容,但是不起作用。任何的想法?

Gra*_*ant 6

Off-answer, but ref for Googlers -用于查找类和删除类的vanilla Javascript 选项

// Finding all elements of a class (creates an array of results)
let x = document.getElementsByClassName("today");

// If it exists, remove it.
if(x.length > 0) { x[0].classList.remove("today"); }
Run Code Online (Sandbox Code Playgroud)


gur*_*deb 5

您已经编写了“ .instructionRow”,但根据html,它应该是“ .instructionRow”。并使用$(this)引用被单击的元素。而且使用'on'(https://api.jquery.com/on/)更好...

$(document).ready(function () {
    $(".instruction").on('click', function(e){
        $(this).find('.details').removeClass("hidden");
    });
});
Run Code Online (Sandbox Code Playgroud)