I have a table
我有一张桌子
I can already get the id of tr (blue box in the picture)
我已经可以获得tr的id(图片中的蓝色框)
I want to add display:none
to the style of tag <i>
through the id (red box in the picture)
我想通过id在标签<I>的样式中添加display:none(图片中的红色框)
This is my idea, I wonder if it can be done?
这是我的主意,我想知道能不能做到?
Or how should I accomplish it?
或者我应该如何完成它?
tr may have 0 or more, so id may also have 0 or more
tr可能有0个或更多,因此id也可能有0或更多
Thanks
谢谢
更多回答
Please edit your question to show the actual HTML (as text, not a picture). Explain which data you have and describe accurately which element(s) in particular you want to target
请编辑您的问题以显示实际的HTML(以文本形式,而不是图片形式)。解释你有哪些数据,并准确描述你想要针对的特定元素
tr may have 0 or more . What they have?
tr可以具有0或更多。他们有什么?
Please visit the help center, take the tour to see what and How to Ask. Do some research. If you get stuck, post a minimal reproducible example of your attempt, noting input and expected output using the [<>] snippet editor.
请访问帮助中心,参观了解如何询问。做一些调查。如果遇到问题,请发布一个可重复的尝试示例,使用[<>]代码段编辑器记录输入和预期输出。
@CodeThing They are like blue and red boxes. The difference is that the id of tr is different and some of the values inside are different.
@CodeThing它们就像蓝色和红色的盒子。不同之处在于tr的id不同,并且一些值内部是不同的。
优秀答案推荐
If you've got the <tr>
ID and want to target the first <i>
element within the 2nd <td>
, you can use a fairly simple query selector
如果您有ID,并且希望以第二个中的第一个元素为目标,那么可以使用一个相当简单的查询选择器
const id = "b24214a8f170cef7.txt";
const el = document.getElementById(id)?.querySelector("td:nth-child(2) > i");
if (el) {
el.style.display = "none";
}
<table border="1">
<tr id="b24214a8f170cef7.txt">
<td>(...)</td>
<td>
<i>I am the <i> tag</i>
<a href="#">Some link</a>
</td>
<td> </td>
</tr>
<tr id="b24214b8f170cef7.txt">
<td>(...)</td>
<td>
<i>I am the <i> tag</i>
<a href="#">Some link</a>
</td>
<td> </td>
</tr>
</table>
更多回答
我是一名优秀的程序员,十分优秀!