我有一个“反馈小部件”,我想为低分辨率屏幕隐藏。我的问题是它在<body>
之后正在注入以下代码而没有遇到我尝试的我无法隐藏reformal_tab
元素
<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/
代码:
<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/
答案 0 :(得分:3)
第二个电话是有效电话。 #
通过 id 引用该元素。
$('#reformal_tab').hide();
文档准备好后,您还需要调用它。
$(function() {
$('#reformal_tab').hide();
});
为什么不在注入时将其隐藏起来,然后你可以将其显示为更高分辨率的屏幕?
<a id="reformal_tab" style="display:none;" href="http://domain.com" ...
然后在你的脚本的某个地方..
if(highResolution) {
$("#reformal_tab").show();
}
答案 1 :(得分:0)
为什么不将它删除?
$('#reformal_tab').remove();
答案 2 :(得分:0)
如果元素是用javascript注入的,那么它可能在DOM就绪后动态插入。解决方案相当简单,在你的CSS中:
#reformal_tab {display: none;}