如果使用jQuery进行移动浏览器,请从dom中移除HTML [英] Remove HTML from dom if mobile browser with jQuery
问题描述
这可能吗?我的意思是,我知道你可以使用 display:none;
和媒体查询
,但这并不妨碍节点被加载,这是资源密集型的。我不想隐藏它们,我想删除它们。
这就是为什么我使用它:
<$ ($(window).width()< 600){
$('html')。remove('aside' );
把它放在标题中,但我可以'让它工作。我做错了什么?
PS:我试着用文档准备功能
来使用它,但仍然无法工作我的 iPhone
。我一直看到放在侧边
。
PS 2:jQuery被加载到标题中,我试图把这段代码在jQuery调用之下。
使用CSS,您告诉浏览器忽略元素的样式,但使用jQuery您告诉浏览器进行交互和操作元素,所以我的猜测是你会以这种方式获得更糟糕的表现。
Is this possible? I mean, I know you can use display: none;
with media queries
, but that does not prevent the nodes to be loaded, which is resource intensive. I don't want to hide them, I want to remove them.
That's why I used this:
function removeit() {
if ($(window).width() < 600) {
$('html').remove('aside');
}
}
And put it in the header, but I can't get it to work. What am I doing wrong?
PS: I tried using it with document ready function
, but still not working on my iPhone
. I keep seeing the aside sidebar
.
PS 2: jQuery is loaded in the header, I have tried to put this snippet beneath the jQuery call.
jQuery executes after the DOM is loaded. So the sidebar is loaded either way.
With CSS, you tell the browser to ignore styling the element but with jQuery you tell the browser to interact and manipulate the element, so my guess is you would actually get worse performance this way.
这篇关于如果使用jQuery进行移动浏览器,请从dom中移除HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!