[英]Deleting an element based on window width
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
如果要在調整窗口大小時刪除它,則需要收聽調整大小:
$(window).on('resize', function() {
if($(window).width() < 768)
$('your_element').remove;
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.