jQuery。从移除的元素导航
假设我有:jQuery。从移除的元素导航,jquery,Jquery,假设我有: <div> <input type="button"> </div> <img src="path/to/img.jpg"> 当我想删除元素时,如何以类似的方式导航到图像 $('input[type="button"]').remove().parent().next('img').hide(); 这没用 小提琴: TLDR:删除元素后是否可以从当前位置继续导航DOM?可以先保存父项:var divParent=$('inp
<div>
<input type="button">
</div>
<img src="path/to/img.jpg">
当我想删除元素时,如何以类似的方式导航到图像
$('input[type="button"]').remove().parent().next('img').hide();
这没用
小提琴:
TLDR:删除元素后是否可以从当前位置继续导航DOM?可以先保存父项:
var divParent=$('input[type=“button”]”)。parent()
然后删除元素并使用divParent.next('img').hide()访问图像
您可以先保存父项:var divParent=$('input[type=“button”]”)。parent()
然后删除元素并使用divParent.next('img').hide()访问图像
您可以先保存父项:var divParent=$('input[type=“button”]”)。parent()
然后删除元素并使用divParent.next('img').hide()访问图像
您可以先保存父项:var divParent=$('input[type=“button”]”)。parent()
然后删除元素并使用divParent.next('img').hide()访问图像代码>在删除第一个元素之前,可以获取第二个元素:
var second = $('input[type="button"]').parent().next('img');
$('input[type="button"]').remove();
second.hide();
在删除第一个元素之前,可以获取第二个元素:
var second = $('input[type="button"]').parent().next('img');
$('input[type="button"]').remove();
second.hide();
在删除第一个元素之前,可以获取第二个元素:
var second = $('input[type="button"]').parent().next('img');
$('input[type="button"]').remove();
second.hide();
在删除第一个元素之前,可以获取第二个元素:
var second = $('input[type="button"]').parent().next('img');
$('input[type="button"]').remove();
second.hide();
您可以将图像保存在局部变量中,然后根据需要使用它
var image = $(this).parent().next('img');
$(this).remove();
image.hide();
检查更新的JSFIDLE:
您可以将图像保存在局部变量中,然后根据需要使用它
var image = $(this).parent().next('img');
$(this).remove();
image.hide();
检查更新的JSFIDLE:
您可以将图像保存在局部变量中,然后根据需要使用它
var image = $(this).parent().next('img');
$(this).remove();
image.hide();
检查更新的JSFIDLE:
您可以将图像保存在局部变量中,然后根据需要使用它
var image = $(this).parent().next('img');
$(this).remove();
image.hide();
检查更新的JSFIDLE:
删除元素后无法链接
你喜欢吗
$(function(){
$('#ex1').click(function(){
$(this).hide().parent().next('img').hide();
});
$('#ex2').click(function(){
//hide image
$(this).parent().next('img').hide();
//then remove
$(this).remove()
});
})
删除图元后不能进行链操作
你喜欢吗
$(function(){
$('#ex1').click(function(){
$(this).hide().parent().next('img').hide();
});
$('#ex2').click(function(){
//hide image
$(this).parent().next('img').hide();
//then remove
$(this).remove()
});
})
删除图元后不能进行链操作
你喜欢吗
$(function(){
$('#ex1').click(function(){
$(this).hide().parent().next('img').hide();
});
$('#ex2').click(function(){
//hide image
$(this).parent().next('img').hide();
//then remove
$(this).remove()
});
})
删除图元后不能进行链操作
你喜欢吗
$(function(){
$('#ex1').click(function(){
$(this).hide().parent().next('img').hide();
});
$('#ex2').click(function(){
//hide image
$(this).parent().next('img').hide();
//then remove
$(this).remove()
});
})
TLDR:否。元素已从DOM中删除。它不再有父元素了。缓存元素、隐藏img然后删除元素有什么不对?如果选择器更简单,您可以只使用.addBack
,但这些元素的顺序感觉很尴尬。TLDR:不。元素已从DOM中删除。它不再有父元素了。缓存元素、隐藏img然后删除元素有什么不对?如果选择器更简单,您可以只使用.addBack
,但这些元素的顺序感觉很尴尬。TLDR:不。元素已从DOM中删除。它不再有父元素了。缓存元素、隐藏img然后删除元素有什么不对?如果选择器更简单,您可以只使用.addBack
,但这些元素的顺序感觉很尴尬。TLDR:不。元素已从DOM中删除。它不再有父元素了。缓存元素、隐藏img然后删除元素有什么不对?如果选择器更简单,您可以只使用.addBack
,但这样的顺序让人感觉很尴尬。