开发者

How do I remove the parent element?

开发者 https://www.devze.com 2023-01-19 00:19 出处:网络
I\'m brand new to jquery and am not even sure if I\'m referring cor开发者_高级运维rectly to the \"parent\" element. I want to remove the two <li> tags completely. Is there a way to do this with

I'm brand new to jquery and am not even sure if I'm referring cor开发者_高级运维rectly to the "parent" element. I want to remove the two <li> tags completely. Is there a way to do this with only a single id declaration?

<li class="remove"><a href="#">ds</a></li>
<li class="remove"><a href="#">xfg</a></li>

<li><a href="#">ds</a></li>   <------This stays as well as the one below
<li><a href="#">xfg</a></li>


you can do

$('.remove').remove(); // all which matches a class="remove" will be gone completely.

or by click of it's <a>

$('#ulID li a').click(function(){
   $(this).closest('.remove').remove();
   return false; // prevent link to jump to a page.
});

Welcome to stackoverflow.com
Don't forget to accept an answer


$('.remove').remove()
0

精彩评论

暂无评论...
验证码 换一张
取 消