[英]JS: How to hide parent div with multiple nested divs, based on child div's content
Here's the code I'm looking at: 这是我正在查看的代码:
<div class="blotter_workshopitempublished blotter_entry">
<div class="blotter_author_block">
<div class="blotter_avatar_holder">
<a href="https://steamcommunity.com/profiles/steam_profile_id">
<div class="playerAvatar online">
<img src="https://steamcdn-a_medium.jpg" data-miniprofile="number">
</div>
</a>
</div>
<div>
<a href="https://steamcommunity.com/profiles/steam_profile_id" data-miniprofile="number">nickname</a>
</div>
<div>
added an item to their favorites </div>
</div>
I'd like to hide all occurrences of "blotter_workshopitempublished blotter_entry" based on "steam_profile_id" or "nickname" (one or the other, I don't care, but "id" would be better), which are inside nested divs. 我想隐藏所有基于“ steam_profile_id”或“昵称”(我不在乎,但最好使用“ id”)的“ blotter_workshopitempublished blotter_entry”出现在嵌套div中。
I looked at several other similar questions but still need help; 我看了其他几个类似的问题,但仍然需要帮助。 I'll use this inside a Tampermonkey script. 我将在Tampermonkey脚本中使用它。
Thanks 谢谢
Something like this should help: 这样的事情应该有所帮助:
const blotters = document.querySelectorAll('.blotter_workshopitempublished.blotter_entry');
blotters.forEach(blotter => {
const id = blotter.querySelector('a').href.split('/').pop();
if (id === "put whatever id you want to hide in here") {
blotter.style.display = "none";
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.