最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - Hide a specific H2 id using javascript or CSS - Stack Overflow

programmeradmin3浏览0评论

We're looking into Zendesk for our support site but it's not very customizable. I'm trying to remove specific text from the page using their widgets function (which can be created in javascript or css).

I'm trying to hide the following h2 tag while displaying the page:

<h2 id="search_box">Knowledge Base &amp; Forums</h2>

I've tried the following CSS:

.search_box {
    display: none;
}

But it doesn't seem to work. I'm not great with either CSS or javascript and I also don't know exactly when these widgets run, but I assume I'm doing something wrong in terms of accessing the element on the page.

I've been able to hide the text using the following bination of Javascript and CSS codes, but it doesn't do what I need because it will hide any part of the page that has the text in it:

Javascript:

$j('h2:contains(Knowledge Base & Forums)').addClass('forumtitle');

CSS:

.forumtitle {
    display: none;
}

Thanks for any help!

We're looking into Zendesk for our support site but it's not very customizable. I'm trying to remove specific text from the page using their widgets function (which can be created in javascript or css).

I'm trying to hide the following h2 tag while displaying the page:

<h2 id="search_box">Knowledge Base &amp; Forums</h2>

I've tried the following CSS:

.search_box {
    display: none;
}

But it doesn't seem to work. I'm not great with either CSS or javascript and I also don't know exactly when these widgets run, but I assume I'm doing something wrong in terms of accessing the element on the page.

I've been able to hide the text using the following bination of Javascript and CSS codes, but it doesn't do what I need because it will hide any part of the page that has the text in it:

Javascript:

$j('h2:contains(Knowledge Base & Forums)').addClass('forumtitle');

CSS:

.forumtitle {
    display: none;
}

Thanks for any help!

Share Improve this question edited Mar 30, 2011 at 17:40 Charles 51.4k13 gold badges106 silver badges144 bronze badges asked Feb 18, 2011 at 4:28 mjdthmjdth 6,5466 gold badges40 silver badges44 bronze badges 0
Add a ment  | 

5 Answers 5

Reset to default 5
#search_box {
    display: none;
}

. is for classes, # is for ids

Try using in your CSS:

#search_box {
    display: none;
}

If you wish to use jQuery you can try this...

$(document).ready(function(){
    $("h2").each(function(){
        if(trim($(this).html()) == "Knowledge Base & Forums") {
            $(this).hide();
        }
    });
});

Your CSS is off - to hide an id `search_box your CSS would be

#search_box {
    display: none;
}

Note the # for id - . is for classes.

Try document.getElementByID("search_box").style.visibility = 'hidden'; in Javascript

发布评论

评论列表(0)

  1. 暂无评论