gpt4 book ai didi

javascript - 根据窗口宽度删除元素

转载 作者:行者123 更新时间:2023-11-28 15:23:24 25 4
gpt4 key购买 nike

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

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

我该如何定位这个元素并删除它?

这是有效的 JavaScript 吗?

谢谢!

最佳答案

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

$('#linkFullWidth').remove(); //if the elements ID is 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

关于javascript - 根据窗口宽度删除元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30255952/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com