Solved

remove li with a spesific id in Jquery

Posted on 2011-09-07
7
614 Views
Last Modified: 2012-05-12
I needto remove li with a specific id but it does not work..

Here is what I using
$("li[@id=" + $(this).val() + ']').remove();
0
Comment
Question by:erikTsomik
  • 4
  • 3
7 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36496867
$("li#" + $(this).val()).remove();

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

0
 
LVL 19

Author Comment

by:erikTsomik
ID: 36496874
I use this and it works
$("li[id=" + $(this).val() + ']').remove();
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36496882
the ID selector is : #

0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 19

Author Comment

by:erikTsomik
ID: 36496896
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
 
LVL 82

Expert Comment

by:leakim971
ID: 36496913
Why a new question?
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 36496923
it just a part of it
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36497103
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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
This article discusses how to create an extensible mechanism for linked drop downs.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now