![](/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.