如何在 JavaScript 中隐藏没有 id 的特定 div 元素?

How can I hide an specific div element without id in JavaScript?

我想知道如何在 Javascript 中隐藏和元素 DIV 而没有 ID。

这是代码:

<div onclick='hideElement(this);'><b>Element 1</b>
Text 1
</div>
<div onclick='hideElement(this);'><b>Element 2</b>
Text 2
</div>
...

谢谢!

function hideElement(element){
    element.style.display = "none";
}

由于您将 this 作为参数传递,因此您不需要 'catch' 其 ID

中的元素