Javascript 基于窗口宽度删除元素 var$linkFullWidth=$('div.image--link'); 如果($(窗口).width()

Javascript 基于窗口宽度删除元素 var$linkFullWidth=$('div.image--link'); 如果($(窗口).width(),javascript,jquery,Javascript,Jquery,我如何定位此元素并删除它 这是有效的JavaScript吗 谢谢 使用jQuery删除元素,因为您已经在使用它 var $linkFullWidth = $('div.image--link'); if($(window).width() < 768){ // Delete the element $linkFullWidth } 或 既然您已经在变量中缓存了它,那么 $('.linkFullWidth').remove(); //if the elements CLASS i

我如何定位此元素并删除它

这是有效的JavaScript吗


谢谢

使用jQuery删除元素,因为您已经在使用它

var $linkFullWidth = $('div.image--link');

if($(window).width() < 768){
    // Delete the element $linkFullWidth
}

既然您已经在变量中缓存了它,那么

$('.linkFullWidth').remove(); //if the elements CLASS is linkFullWidth(will delete all elements with this class though)

使用jQuery删除元素,因为您已经在使用它

var $linkFullWidth = $('div.image--link');

if($(window).width() < 768){
    // Delete the element $linkFullWidth
}

既然您已经在变量中缓存了它,那么

$('.linkFullWidth').remove(); //if the elements CLASS is linkFullWidth(will delete all elements with this class though)

如果要在窗口调整大小时将其删除,则需要收听调整大小:

$($linkFullWidth).remove(); //would do the job just fine
$(窗口).on('resize',function()){
如果($(窗口).width()<768)
$('your_element')。删除;
});

如果要在调整窗口大小时将其删除,则需要收听调整大小:

$($linkFullWidth).remove(); //would do the job just fine
$(窗口).on('resize',function()){
如果($(窗口).width()<768)
$('your_element')。删除;
});

是否要删除或隐藏该元素?我建议您使用CSS媒体查询,不要删除该元素。如果删除,则不会还原该元素。需要再次重新加载页面。如果页面中包含jQuery,则它是有效的javascript。是否要删除或隐藏该元素?我建议您使用CSS媒体查询。如果删除该元素,则不会还原该元素。需要重新加载页面。如果页面中包含jQuery,则该页面是有效的javascript。