04
2018
08

jquery删除元素

<div class="anco">

<p id="rb">喜欢钱</p>

<p id="rb2">我喜欢钱</p>

<p id="rb3">我很喜欢钱</p>

<p id="rb4">我很喜欢有钱</p>

<p id="rb5">我很喜欢有很多钱</p>

<p id="rb6">我真的很喜欢有很多钱</p>

<div class="xb">

<div class="cc">ca</div>

</div>

</div>

<input type="button" id="wxrb" value="删除元素" />

<input type="button" id="wxgnr" value="删除元素内的所有元素" />

<input type="button" id="rnhm" value="过滤删除元素内的某个标签" />

<input type="button" id="wokao" value="删除元素下的别的元素" />

<input type="button" id="wgsn" value="删除元素下的别的元素" />


<script type="text/javascript">

$(document).ready(function(){

$('#wxrb').click(function(){

$('.anco').remove();

});

$('#wxgnr').click(function(){

$('.anco').empty();

});

$('#rnhm').click(function(){

$('.anco p').remove('#rb')//删除anco这个div下的p标签名为rb的元素,如果remove('p')则是删掉全部是p标签的元素

});

$('#wokao').click(function(){

$('.anco .xb').remove('.xb')//删除div为anco的元素下面为xb的元素

});

$('#wgsn').click(function(){

$('.xb .cc').remove('.cc')

})

});

</script>


« 上一篇下一篇 »