简体   繁体   English

隐藏Div:“ display:none”属性

[英]Hide a Div: “display:none” property

Suppose there is a string of Divs with no ID or name to distinguish them. 假设有一串Divs,没有ID或名称来区分它们。 Like the code bellow: 就像下面的代码:

<div>
<input value="0" name="checkFerramentas[]" id="checkFerramentas" title="Exportar todas operações cadastradas em Compras e Vendas" onclick="checkFerramentas_checkBox_para_textBox(5);" type="CHECKBOX">
</div>

<div>
<input value="1" name="checkFerramentas[]" id="checkFerramentas" title="Exportar parâmetros definidos em Cadastro Geral" onclick="checkFerramentas_checkBox_para_textBox(5);" type="CHECKBOX">
</div>

<div>
<input value="2" name="checkFerramentas[]" id="checkFerramentas" title="Exportar liberações/bloqueios de APR" onclick="checkFerramentas_checkBox_para_textBox(5);" type="CHECKBOX">
</div>

How to hide the second DIV without adding a ID to it? 如何在不添加ID的情况下隐藏第二个DIV? This HTML is generated by a function which I can't edit. 此HTML是由我无法编辑的函数生成的。 Is there any HTML or JS to hide it from "outside"? 是否有任何HTML或JS将其隐藏在“外部”?

This could be a forced solution using CSS pseudo-selectors but its works, good look 这可能是使用CSS伪选择器的强制解决方案,但是它的工作原理很好

div:nth-child(2) {
  display: none;
}

div:nth-child(2) will work but there may be more div elements in the page so we may need to be more specific. div:nth-​​child(2)可以使用,但是页面中可能有更多的div元素,因此我们可能需要更具体一些。 for example consider the parent element. 例如考虑父元素。 if parent element has id , it is better. 如果父元素具有id,则更好。

div > div:nth-child(2) { display:none; }

or 要么

#parentid > div-child(2) { display:none; }

you can extend the solution. 您可以扩展解决方案。

As a stab in the dark (since you haven't provided much information), what you might really want to do is hide the div containing the input with title "Exportar parâmetros definidos em Cadastro Geral". 作为一个暗中的刺探(因为您没有提供太多信息),您可能真正想做的是隐藏包含标题为“ Exportarparâmetrosdefinidos em Cadastro Geral”的输入的div。 To do that you could do: 为此,您可以执行以下操作:

var input = document.querySelector('input[title="Exportar parâmetros definidos em Cadastro Geral"]');
var div = input && input.parentNode; 
div.style.display = 'none';

Of course there are many other ways too. 当然,还有许多其他方法。

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

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