繁体   English   中英

当标题与页面标题匹配时,如何删除带有类的元素?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM