jQuery:隐藏元素 [英] jQuery: hide element

查看:26
本文介绍了jQuery:隐藏元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个反馈小部件",我想为低分辨率屏幕隐藏它.我的问题是它在 <body> 之后立即注入以下代码,但我不知道我尝试了什么,我无法隐藏 reformal_tab 元素

I have a "feedback widget" that i want to hide for low resolution screens. my problem is that it's injecting the following code right after <body> and no metter what i try i can't hide reformal_tab element

<a id="reformal_tab" href="http://domain.com" onclick="Reformal.widgetOpen();return false;" onmouseover="Reformal.widgetPreload();" onmouseout="Reformal.widgetAbortPreload();"><img alt="" src="domain.com/tab.png"></a>

我的尝试

<script>
        $('reformal_tab').hide();
        $('#reformal_tab').hide();
</script>

这是实际的小部件,如果它可以帮助http://reformal.ru/

this is the actual widget if that can help http://reformal.ru/

代码:

<script type="text/javascript">
$(function() {
    $('#reformal_tab').hide();
});

    var reformalOptions = {
        project_id: 93459,
        project_host: "domain.com",
        tab_orientation: "left",
        tab_indent: "50%",
        tab_bg_color: "#F05A00",
        tab_border_color: "#FFFFFF",
        tab_border_width: 2
    };

    (function() {
        var script = document.createElement('script');
        script.type = 'text/javascript'; script.async = true;
        script.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'media.reformal.ru/widgets/v3/reformal.js';
        document.getElementsByTagName('head')[0].appendChild(script);
    })();
</script>

你可以在这里看到它http://jsfiddle.net/PQsQq/2/

推荐答案

第二个调用是有效的.# 通过 id 引用元素.

The second call is the valid one. The # references the element by id.

$('#reformal_tab').hide();

您还需要在文档准备好后调用它.

You'll also need to call it when the document is ready.

$(function() {
    $('#reformal_tab').hide();
});

你为什么不在注入时隐藏它,然后你可以在更高分辨率的屏幕上显示它?

Why don't you just make it hidden when you inject it, and then you can show it for higher res screens?

<a id="reformal_tab" style="display:none;" href="http://domain.com" ...

然后在脚本中的某个地方..

Then somewhere in your script..

if(highResolution) {
  $("#reformal_tab").show();
}

这篇关于jQuery:隐藏元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆