remove li with a spesific id in Jquery

I needto remove li with a specific id but it does not work..

Here is what I using
$("li[@id=" + $(this).val() + ']').remove();
LVL 19
erikTsomikSystem Architect, CF programmer Asked:
Who is Participating?
 
leakim971Connect With a Mentor PluritechnicianCommented:
$("li#" + $(this).val()).remove();

should work (a unique ID per element) :
$("#" + $(this).val()).remove();

0
 
erikTsomikSystem Architect, CF programmer Author Commented:
I use this and it works
$("li[id=" + $(this).val() + ']').remove();
0
 
leakim971PluritechnicianCommented:
the ID selector is : #

0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
erikTsomikSystem Architect, CF programmer Author Commented:
My html code is this . How would I remove all elements not just li but ul an label
<label></label>
<ul class="options">
<li id="1">John</li>
</ul>
0
 
leakim971PluritechnicianCommented:
Why a new question?
0
 
erikTsomikSystem Architect, CF programmer Author Commented:
it just a part of it
0
 
leakim971PluritechnicianCommented:
erikTsomik thanks for your answer.

I suppose you want to remove label and ul around the given LI

    <label></label>
    <ul class="options">
         <li id="1">John</li>
    </ul>

I think you shoud use a container for all :

<div class=".containerClass">
    <label></label>
    <ul class="options">
         <li id="1">John</li>
    </ul>
</div>

and now you can use :

$("#" + $(this).val()).closest(".containerClass").remove(); // or if you really prefer your syntax (not recommended) : $("li[id=" + $(this).val() + ']').closest(".containerClass").remove();

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.