[英]Hide a table row if a cell inside contains a specific word
I would like to be able to hide a table row, only if a cell inside the table contains the word Complimentary, on all pages in my website.我希望能够隐藏表格行,仅当表格内的单元格在我网站的所有页面上包含“免费”一词时。
An example page is here: https://widac.com.au/event/widac-event/示例页面在这里: https : //widac.com.au/event/widac-event/
this picture shows the part I was to be hidden from view:这张照片显示了我要隐藏的部分:
if anyone can tell me how to do this - it would be greatly appreciated!如果有人能告诉我如何做到这一点 - 将不胜感激!
$('#tblId tr').each(function() {
$(this).find('td')..each(function() {
if (this.textContent.includes('Complimentary')) {
$(this).parent().hide();
}
});
});
#tblId
is id of that particular table and i iterate on tr and inside each of tr, i invoke each of td, i match the content and hide that particular tr #tblId
是该特定表的 id,我在 tr 和每个 tr 内部迭代,我调用每个 td,我匹配内容并隐藏该特定 tr
javascript: javascript:
document.querySelectorAll('td').forEach(function(td) {
if (td.textContent.includes('Complimentary')) {
td.parentElement.style.display = 'none';
}
});
jQuery: jQuery:
$('td').each(function() {
if (this.textContent.includes('Complimentary')) {
$(this).parent().hide();
}
});
Although in your example site, .tribe-tickets-form-row
has display: block !important
, which overrides this.尽管在您的示例站点中, .tribe-tickets-form-row
具有display: block !important
,它会覆盖它。 You could set .opacity = 0
, although it would still be interactable.您可以设置.opacity = 0
,尽管它仍然是可交互的。 Or you could just straight up .remove()
it.或者你可以直接.remove()
它。
$(".tribe-events-tickets tr").each( function (el) {
$(this).children().each(function () {
var text = $(this).text();
if (text.indexOf("Complimentary") !== -1 ) {
$(this).parent().hide();
}
});
});
This can help, but at first this CSS rule in your code should be modified:这会有所帮助,但首先应修改代码中的此 CSS 规则:
.tribe-tickets-form-row {
margin-top: 20px;
display: block !important;
}
remove the '!important', it doesn't allow to hide elements.删除 '!important',它不允许隐藏元素。 I hope it'll help.我希望它会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.