![](/img/trans.png)
[英]How can I parse a document and remove all elements except for one that matches and ID and its children
[英]How can I remove elements with a class when its header matches the page title?
$(document).ready(function () {
var pageTitle = $('h3.title-hidden');
if (title === pageTitle) {
$('.content-hidden').remove();
}
});
我的错误在哪里?
pageTitle
是包装h3
元素的jQuery对象。 它不包含该元素的文本 。 如果需要文本,请使用.text()
:
var pageTitle = $('h3.title-hidden').text();
根据您的代码,这假定页面上仅h3.title-hidden
了一个h3.title-hidden
元素,并且如果该元素的文本与文档标题匹配,则您希望删除所有.content-hidden
元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.